佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 984|回复: 1

c++ 初学者需要你们的帮忙...

[复制链接]
发表于 23-8-2008 11:34 AM | 显示全部楼层 |阅读模式
我是c++的初学者哦~当然也是第一次用C++的咯~
我的问题如下...

develop a program that will determine the gross pay for each several employees.
the company pays "straight time" for the first 40 hours worked by each employee and
pays "time-and-a-half" for all hours worked in excess of 40 hours in rate of rm10
per hour. You are given a list of the employees of the company, the number of hours
each employee worked last week and the hourly rate of each employee. and should
determine and display the employee's gross pay. Below is a simple input/output
dialog:

Enter number of hours worked ( -1 to end): 39
salary is rm390.00
Enter number of hours worked ( -1 to end):40
salary is rm400.00
Enter number of hours worked ( -1 to end):41
salary is rm415.00
Enter number of hours worked ( -1 to end):-1

and my code is:
# include <iostream>

using std::cout;
using std::cin;

int main()
{
&#160; &#160; int integer1;
&#160; &#160; int total1;
&#160; &#160; int total2;
&#160; &#160; int total3;
&#160; &#160;
&#160; &#160; cout << "pls enter lol";
&#160; &#160; cin >> integer1;
&#160; &#160;
&#160; &#160;&#160; &#160;&#160;&#160;if (integer1 <= 40)
&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;total1 = integer1 * 10;
&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;cout << "total = " <<total1;
&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;
&#160; &#160;&#160; &#160;&#160;&#160;if (integer1 > 40)
&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;total2 = integer1 * 10;
&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;total3 = (integer1 - 40) * 15 + total2;
&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;cout << "total = " << total3;
&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;
&#160; &#160;&#160; &#160;&#160;&#160;system("AUSE";
&#160; &#160;&#160; &#160;&#160;&#160;return 0;
&#160; &#160;&#160; &#160;&#160;&#160;
}

who can help me check it?
and tell me where i wrong?
i just know my system("AUSE" wrong o~
thx for all who help me

[ 本帖最后由 jason718 于 23-8-2008 12:32 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 23-8-2008 01:28 PM | 显示全部楼层
当你的 if() 之后的 statement 是超过1行(一行的意思是“从statement的开始到 ; (semicolon)出现为止)的话,请用curly bracket {} 来包围着你对应该 if() 的 statement。
  1. if (integer1 <= 40)
  2. {
  3.             total1 = integer1 * 10;
  4.             cout << "total = " <<total1;
  5. }

  6. 以及

  7. if (integer1 > 40)
  8. {
  9.             total2 = integer1 * 10;
  10.             total3 = (integer1 - 40) * 15 + total2;
  11.             cout << "total = " << total3;
  12. }
复制代码
否则compiler只会把 if()之后的第一行statement 和 if()联系起来,其他的都会被当作不相干的独立statement 。

还有,以后当你要在论坛放出你的源代码,请使用 code block,也就是

[ code ] 你的源代码 [ /code ]

这会让你的源代码比较容易阅读,就好像我在上面使用的那样。

[ 本帖最后由 geekman 于 23-8-2008 01:31 PM 编辑 ]
回复

使用道具 举报

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

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-12-2025 03:04 PM , Processed in 0.088246 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表