Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with my code

Status
Not open for further replies.

dtaylor01

Programmer
Oct 14, 2008
2
Can someone take a look at my code. I'm having some errors and do not know how to correct. Not looking for someone to give me the answer, but walk me though to better understand.
This is a compiler to compute wages.

Code:
#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[ ])
{ 

int a = 40;		            //No. of hrs worked during week
float b = 12.75;       		//Pay rate: dollars per hour
float c = 510;
cout << a * b;
cout << c;

//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 << "Hourly pay rate (specify two digits after the decimal point) = ";
cin >> pay_rate;

// compute wages

sum = (number of hours * pay rate);

// display the result

cout << endl;
cout << "The weekly wages are: $" << wages << endl;

return (0); // terminate with success

}
 
It would help if you also posted the errors you're getting.
From what I can see though, you haven't declared these variables anywhere:
hours_worked, pay_rate, sum, wages

and then you have (number of hours * pay rate) which makes absolutely no sense whatsoever.
 
Have I no errors now. But is this on the right track now?

Code:
[#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[ ])
{ 

//cout << "hours worked: ";       //No. of hrs worked during week
//cin >> 40;
//cout << " pay rate: $"; per hour	//Pay rate: dollars
//cin >> 12.75;
//cout << "weekly wages: ";             //Weekly wages
//cin >> 510;

// 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 << "Hourly pay rate (specify two digits after the decimal point) = ";
//cin >> pay_rate;

// compute wages

//weekly_wages = computewages (hours,rate,sum );

// display the result

cout << endl;
//cout << "The weekly wages are: $" << wages << endl;

return (0); // terminate with success

}]
 
Well commenting out the lines that give you errors will get it to compile, but I doubt it does what you want.
It would be better to fix the errors rather than just commenting them out. i.e. declare the variables before you start using them.

Also, you should put [ignore]
Code:
[/ignore] tags around your code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top