Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
楼主: 虚空使者
打印 上一主题 下一主题

Term 2了。。。開始學web development了。。有問題會問

[复制链接]

5

主题

0

好友

1万

积分

荣誉会员

さてだ ...どうしよう?

Rank: 50Rank: 50Rank: 50Rank: 50Rank: 50

31#
发表于 2008-11-4 09:32 PM |只看该作者

回复 #30 Super-Tomato 的帖子

就float pay;
double我沒學過。。。是怎樣的command?
然后可以if(choice=='Y','y')這樣用嗎?


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

32#
发表于 2008-11-5 06:51 AM |只看该作者
原帖由 虚空使者 于 2008-11-4 09:32 PM 发表
就float pay;
double我沒學過。。。是怎樣的command?
然后可以if(choice=='Y','y')這樣用嗎?



double 類型沒學過也太牽強些了吧?
把 choice 轉換成小寫或大寫字母比對就可解決


回复

使用道具 举报

5

主题

0

好友

1万

积分

荣誉会员

さてだ ...どうしよう?

Rank: 50Rank: 50Rank: 50Rank: 50Rank: 50

33#
发表于 2008-11-10 05:45 PM |只看该作者
完了。。。
今天去show demo給lecturer看
他說我的program還不夠convenient for the user
要我改更convenient的。。。
我想到頭快爆炸了
請高人指點我好嗎
  1. #include<iostream>
  2. using namespace std;

  3. int main()
  4. {
  5. int a,b,c,d,i,j,k,l;
  6. double pay;
  7. cout<<"Please enter the number of managers\n";
  8. cin>>a;
  9. cout<<"Please enter the number of hourly workers\n";
  10. cin>>b;
  11. cout<<"Please enter the number of commission workers\n";
  12. cin>>c;
  13. cout<<"Please enter the number of piece workers\n";
  14. cin>>d;

  15. if(a>0)
  16. {
  17. cout<<"Please enter the 1st manager weekly salary\n";
  18. cin>>i;
  19. cout<<"The 1st manager weekly salary is [        DISCUZ_CODE_0        ]quot;<<i<<"\n";
  20. }
  21. if(a=0)
  22. {
  23. cout<<"There were no managers working in this week\n";
  24. }
复制代码
我的想法是在頭直接input每個position有多少個employee
然后下面再慢慢input
假設我的a5
我要如何讓這個出現?(例子)
cout<<"Please enter the 1st manager weekly salary\n";
cin>>i;
cout<<"Please enter the 2nd manager weekly salary\n";
cin>>i;
cout<<"Please enter the 3rd manager weekly salary\n";
cin>>i;
cout<<"Please enter the 4th manager weekly salary\n";
cin>>i;
cout<<"Please enter the 5th manager weekly salary\n";
cin>>i;

cout<<"The 1st manager weekly salary is $"<<i<<"\n";
cout<<"The 2rd manager weekly salary is $"<<i<<"\n";
cout<<"The 3rd manager weekly salary is $"<<i<<"\n";
cout<<"The 4th manager weekly salary is $"<<i<<"\n";
cout<<"The 5th manager weekly salary is $"<<i<<"\n";


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

34#
发表于 2008-11-10 06:30 PM |只看该作者
原帖由 虚空使者 于 2008-11-10 05:45 PM 发表
完了。。。
今天去show demo給lecturer看
他說我的program還不夠convenient for the user
要我改更convenient的。。。
我想到頭快爆炸了
請高人指點我好嗎#include
using namespace std;

int main()
...



你都說了 a = 5, 那麼就把你的循環儲存在一個 Array 中


回复

使用道具 举报

5

主题

0

好友

1万

积分

荣誉会员

さてだ ...どうしよう?

Rank: 50Rank: 50Rank: 50Rank: 50Rank: 50

35#
发表于 2008-11-10 07:18 PM |只看该作者

回复 #34 Super-Tomato 的帖子

  1. #include<iostream>
  2. using namespace std;

  3. int main()
  4. {
  5. int a,b,c,d,i,j,k,l,y[30],z
  6. double pay;
  7. cout<<"Please enter the number of managers\n";
  8. cin>>a;
  9. cout<<"Please enter the number of hourly workers\n";
  10. cin>>b;
  11. cout<<"Please enter the number of commission workers\n";
  12. cin>>c;
  13. cout<<"Please enter the number of piece workers\n";
  14. cin>>d;

  15. cout<<"Enter the weeklypay for all managers\n";
  16. for(z=0;z<a;z++)
  17. {
  18. cin>>y[z];
  19. }
  20. cout<<"The salary for all the managers are\n";
  21. for(z=0;z<a;z++)
  22. cout<<"$"<<y[z]<<"\n";
复制代码
我這個array只能解決第1類型worker(manager)而已
至于我第2個worker有formula的
i=payrate
j=hoursworked
k=OT payrate(only applicable if hoursworked exceed 40 hours)
l=OT hours worked(only applicable if hoursworked exceed 40 hours, eg work for 50 hours it must automatically count 10 hours as OT hours)
pay = i*j+(1.5*k*l)
我就真的不知道要怎樣做了

[ 本帖最后由 虚空使者 于 2008-11-10 07:20 PM 编辑 ]


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

36#
发表于 2008-11-10 10:54 PM |只看该作者
原帖由 虚空使者 于 2008-11-10 07:18 PM 发表
#include
using namespace std;

int main()
{
int a,b,c,d,i,j,k,l,y[30],z
double pay;
couta;
coutb;
coutc;
coutd;

cout



方法都一樣, 做好所要的計算然後儲存在 Array 中
先後輸入次序就看你自己怎麼設計了


回复

使用道具 举报

5

主题

0

好友

1万

积分

荣誉会员

さてだ ...どうしよう?

Rank: 50Rank: 50Rank: 50Rank: 50Rank: 50

37#
发表于 2008-11-10 11:11 PM |只看该作者

回复 #36 Super-Tomato 的帖子

可以請大大示范第2個worker的code給我看嗎?
我對cin那4個int那里非常混亂
既然只能cin>>y[z]這一種
那我要怎樣把i,j,k,l這4個int放下去?
關于array的東西我們老師并沒有解釋到很深
我也懂得不是很多


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

38#
发表于 2008-11-11 07:42 AM |只看该作者
原帖由 虚空使者 于 2008-11-10 11:11 PM 发表
可以請大大示范第2個worker的code給我看嗎?
我對cin那4個int那里非常混亂
既然只能cin>>y[z]這一種
那我要怎樣把i,j,k,l這4個int放下去?
關于array的東西我們老師并沒有解釋到很深
我也懂得不是很多



你應該去買本書學習基礎, 以下是個簡單的例子自己研究吧


  1. #include<iostream>
  2. using namespace std;

  3. int main()
  4. {
  5.         int iNumber = 0, iMin = 0, i;
  6.         long lTotal = 0;
  7.         double dAverage = 0;

  8.         cout << "Please enter the number of student : ";
  9.         cin >> iNumber;
  10.         cout << "Please enter minimum score : ";
  11.         cin >> iMin;

  12.         int *iScore = new int[iNumber];
  13.         for(i=0; i<iNumber; i++)
  14.         {
  15.                 cout << "Enter student" << i+1 << " test score : ";
  16.                 cin >> iScore[i];
  17.                 lTotal += iScore[i];
  18.         }

  19.         cout << "\n\nResults : \n";
  20.         for(i=0; i<iNumber; i++)
  21.                 if(iScore[i] < iMin)
  22.                         cout << "Student" << i+1 << " need " << iMin - iScore[i] << " marks to reach the goal.\n";

  23.         dAverage = lTotal / iNumber;
  24.         cout << "\nThis class average score is : " << dAverage << "\n";
  25.         system("pause");

  26.         delete[] iScore;
  27.         return 1;
  28. }
复制代码

[ 本帖最后由 Super-Tomato 于 2008-11-11 07:44 AM 编辑 ]


回复

使用道具 举报

5

主题

0

好友

1万

积分

荣誉会员

さてだ ...どうしよう?

Rank: 50Rank: 50Rank: 50Rank: 50Rank: 50

39#
发表于 2008-11-11 10:40 AM |只看该作者

回复 #38 Super-Tomato 的帖子

過了第2個了
但是一直搞不懂第3個worker哪里寫錯
一直出同一個的output給我。。。
  1. #include<iostream>
  2. using namespace std;

  3. int main()
  4. {
  5. int a,b,c,d,i[30],j[30],k[30],z;
  6. double pay;
  7. cout<<"Please enter the number of managers\n";
  8. cin>>a;
  9. cout<<"Please enter the number of hourly workers\n";
  10. cin>>b;
  11. cout<<"Please enter the number of commission workers\n";
  12. cin>>c;
  13. cout<<"Please enter the number of piece workers\n";
  14. cin>>d;

  15. for(z=0;z<a;z++)
  16. {
  17. cout<<"Enter the weeklypay manager "<<z+1<<"\n";
  18. cin>>i[z];
  19. }
  20. for(z=0;z<a;z++)
  21. cout<<"The weeklypay for manager "<<z+1<<" is $"<<i[z]<<"\n";

  22. for(z=0;z<b;z++)
  23. {
  24. cout<<"Enter the payrate for hourly worker "<<z+1<<"\n";
  25. cin>>i[z];
  26. cout<<"Enter the hoursworked for hourly worker "<<z+1<<"\n";
  27. cin>>j[z];
  28. {
  29. if(j[z]<=40)
  30. goto label;
  31. if(j[z]>40)
  32. cout<<"Enter the OT payrate for hourly worker "<<z+1<<"\n";
  33. cin>>k[z];
  34. if(j[z]>40)
  35. cout<<"The hourly worker "<<z+1<<" has benn working for extra "<<j[z]-40<<" hours "<<"\n";
  36. }


  37. label: if(j[z]<=40)
  38. pay = i[z]*j[z];

  39. if(j[z]>40)
  40. pay = i[z]*j[z]+(1.5*k[z]*(j[z]-40));
  41. cout<<"The weekly pay for commission worker "<<z+1<<" is $"<<pay<<"\n";
  42. }

  43. for(z=0;z<c;z++)
  44. {
  45. cout<<"Enter the weekly sales for commission worker "<<z+1<<"\n";
  46. cin>>i[z];
  47. pay=250+(i[z]*0.057);
  48. }
  49. for(z=0;z<c;z++)
  50. cout<<"The weekly pay for commission worker "<<z+1<<" is $"<<pay<<"\n";









  51. return 0;
  52. }
复制代码
出來的是這個。。
可以請大大告訴我哪個地方有問題嗎?
我認為是最后幾段有點問題。。。
我想解決這個了這個第4個worker我就沒問題了


[ 本帖最后由 虚空使者 于 2008-11-11 10:44 AM 编辑 ]


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

40#
发表于 2008-11-11 11:23 AM |只看该作者
for(z=0;z<c;z++)
{
cout<<"Enter the weekly sales for commission worker "<<z+1<<"\n";
cin>>i[z];
pay=250+(i[z]*0.057);
}
for(z=0;z<c;z++)
cout<<"The weekly pay for commission worker "<<z+1<<" is $"<<pay<<"\n";

看清楚紅色部份同以下有甚麼分別嗎?

int a = 0;
for(int i=0; i<10; i++)
{
      a = i;
}

for(int i=0; i<10; i++)
{
     cout << a << "\n";
}


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-25 03:19 PM , Processed in 0.101033 second(s), 20 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部