need help with beginner C++

Dear Summer

Golden Member
Sep 30, 2008
1,015
1
71
I am trying to develop a program to calculate weekly wage

1. how do you give a name to a file with the source code?


2. what is the code to declare the hours_worked as an integer? (no of hours)

is it "int hours_worked;"?


3. is the code to compute the wage correct?




#include <iostream>
using namespace std ;
int main()
{
Int hours_worked;//No. of hrs worked during week
float pay_rate; //Pay rate: dollars per week
float wages; //Weekly wages
// read in the hours worked
cout << endl ;
cout << "Number of hours worked during"
<< " the week (integer) = " ;
cin >> hours_worked ;
// read in the pay rate
cout << "Weekly pay rate (specify two digits "
<< "after the decimal point) = " ;
cin >> pay_rate ;
// compute wages
Wages = hours_worked*pay_rate;

// display the result
cout << endl ;
cout << "The weekly wages are: $" << wages << endl ;
return (0);
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
1) What file are you trying to name? The source file or the executable?

2) Yes that works.

3) Seems about right to me, but I'm not great at eyeballing bugs. Really no error handling, but that may or may not be expected of you.
 

z1ggy

Lifer
May 17, 2008
10,010
66
91
Well..when you compile it.. does it give you errors? I mean.. start there atleast. I havent taken C++ in a while but it looks okay. Probably more complicated than it needs to be though. Im sure some crazy programmer guy on here can help you if you need to debug.
 

Dear Summer

Golden Member
Sep 30, 2008
1,015
1
71
Originally posted by: ObscureCaucasian
1) What file are you trying to name? The source file or the executable?

2) Yes that works.

3) Seems about right to me, but I'm not great at eyeballing bugs. Really no error handling, but that may or may not be expected of you.

1. the source file
3. how about just the part that I bolded?
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
1) You just copy the code into any basic text editor (notepad) and save as <filename>.cpp

2) No, that's wrong, but only slightly. "=" is the assignment operator. The right side of the "=" is computed, and then the value is moved into the wages variable.

NOTE: C/C++ is case-sensitive so:
float wages;

defines the variable, but you then try:
Wages = hours_worked*pay_rate;

There is no "Wages" defined... only "wages" so make the "W" lowercase and you should be okay.
 

Dear Summer

Golden Member
Sep 30, 2008
1,015
1
71
Originally posted by: ObscureCaucasian
1) You just copy the code into any basic text editor (notepad) and save as <filename>.cpp

2) No, that's wrong, but only slightly. "=" is the assignment operator. The right side of the "=" is computed, and then the value is moved into the wages variable.

NOTE: C/C++ is case-sensitive so:
float wages;

defines the variable, but you then try:
Wages = hours_worked*pay_rate;

There is no "Wages" defined... only "wages" so make the "W" lowercase and you should be okay.

so for #2, it should be
"hours_worked = int"?

 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
Originally posted by: Dear Summer
Originally posted by: ObscureCaucasian
1) You just copy the code into any basic text editor (notepad) and save as <filename>.cpp

2) No, that's wrong, but only slightly. "=" is the assignment operator. The right side of the "=" is computed, and then the value is moved into the wages variable.

NOTE: C/C++ is case-sensitive so:
float wages;

defines the variable, but you then try:
Wages = hours_worked*pay_rate;

There is no "Wages" defined... only "wages" so make the "W" lowercase and you should be okay.

so for #2, it should be
"hours_worked = int"?

Sorry I think I was unclear.... The first part is right (float wages; )
what you need is to change is:

Wages = hours_worked*pay_rate;
to
wages = hours_worked*pay_rate;