Need help with first C++ Assignment.

Jan 27, 2008 at 12:09pm
Well the assignment goes like this. I need to get user input for 3 things....
Employee ID (integers)
Number of hours worked (double)
Rates per Hour (double)

Then make it Display the following things

Employee ID
Hours Worked
Rate Per Hour
Gross Salary

and the Program header is required. <---- What is this?
Author's Name
Program Name
Date

Some problems that I am having is that when you include letters for the Empoyee ID, the program will show wierd numbers. Also if you include the $ sign for the rate per hour it also show's wierd numbers. Also if you put alot of numbers for the Employee ID, like 90321930219301 it also messes up the numbers.

This is what I have got so far. Please help me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <string>

using namespace std;

int main()
{

	int EmployeeID;
	double Hours, Dollars2;
	double Dollars;

	cout << "What is your Employee ID? " << endl;
	cin >> EmployeeID;
	cout << "How many hours do you work? " << endl;
	cin >> Hours;
	cout << "How much do you make per hour? " << endl;
	cin >> Dollars;
	cout << "\n";
	cout << "Employee ID: " 
		<< EmployeeID << endl;
	cout << "----------------" << endl;
	cout << "Hours Worked: " 
		<< Hours << endl;
	cout << "----------------" << endl;
	cout << "Rate Per Hour: " 
		<< Dollars << endl;
	cout << "----------------" << endl;
	cout << "Your Gross Salary is: " 
		<< Hours*Dollars << "\n";
	cout << "\n";
	
	return 0;
}
Last edited on Jan 27, 2008 at 1:13pm
Jan 28, 2008 at 12:04am
The Program Header is simply a few lines of comment that include: Author's Name (your name), Program Name(the name of the file/program), Date (program was created).

As far as your problem with displaying random numbers, I am not having that problem with your code at all (I am using Dev-C++) when using integers. Using letters (which are not integers) will give you this problem. If you need to include letters then look into making EmployeeID a String.

The dollar symbol will give you that error since it is not actually part of the double number. You can get it to print a '$' symbol by just adding the $ before print your variables.

On a side note, variable names typically use camelCasing, and start with a lowercase letter. While this is not required, it is considered good coding practice to follow that. Classnames typically start with UpperCase to make them easier to differentiate in larger code.

~maingeek.
Last edited on Jan 28, 2008 at 12:08am
Jan 28, 2008 at 2:20am
Thanks maingeek.

Well the thing is what if the person who is working is not getting paid in dollars but in euros? So I need to make sure that if they include the dollar sign or the euro sign that it will not mess up. And if I just add it in before the print variables it will just be one kind of dollar.
Jan 29, 2008 at 3:16am
Well, I would create a separate character variable to store the Euro/Dollar/Yen symbol and then print it along with the output.

This way you will be able to ask the user to input it, and they can input any char that that wish.

~maingeek.
Topic archived. No new replies allowed.