• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

need help with beginner C++

Dear Summer

Golden Member
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);
 
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.
 
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.
 
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?
 
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.
 
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"?

 
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;
 
Back
Top