Click here to Skip to main content
14,878,738 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this compiles but I am getting the wrong output ex( 5 hours 6/hr should read 30 but I am not getting that outcome I get 687----- for the answer how do I fix this to work properly


#include <iostream>
#include <string>
using namespace std;
class Employee {
private:
	const static int max_hours = 40;
	string firstName;
	string lastName;
	int hours[max_hours];
	int numhours;
	int wadges;
	
	
public:
	// First Name
	string getFirstName() { return firstName; }
	void setFirstName(string name) { firstName = name; }
	void retrieveFirstName() {
		string temp;
		cout << "First Name: ";
		cin >> temp;
		setFirstName(temp);
	}
	// Last Name
	string getLastName() { return lastName;	}
	void setLastName(string name) {	lastName = name; }
	void retrieveLastName() {
		string temp;
		cout << "Last Name: ";
		cin >> temp;
		setLastName(temp);
	}
	// Num hours
	int getnumhours() { return numhours; }
	void setnumhours(int hours){
	if (hours >= 0 && hours <= max_hours){
	
	}else  {
		hours = 0;
	}
	
	}
	
	void retrievehours() {
	cout << "How many hours? ";
	int temp;
	cin >> temp;
	setnumhours(temp);
	}
	// wadges
	int getwadges() {return wadges; }
	void setwadges(int wadges){}
	void retrievewadges(){
	cout << "What is your pay rate? " ;
	int temp;
	cin >> temp;
	setwadges(temp);
	
	}
	void retrieve() {
		retrieveFirstName();
		retrieveLastName();
		retrievehours();
		retrievewadges();
	
		
	}
		int grosspay(){
		int total;
		total = wadges * numhours;	
		
		
		return total ;
}	
};
int main() {
	Employee name;
	name.retrieve();
	cout << "Grosspay " << name.grosspay() << endl;
	system("pause");
	return 0;
}
Posted
Updated 23-Nov-10 14:08pm
v2
Comments
[no name] 23-Nov-10 20:08pm
   
Please remember to properly format any code you post

The first obvious thing is that setnumhours() does nothing (if the hours arg is valid). Fix that and see what happens next.
   
If I compile your code at the maximum warning level /W4, which you should always do, I get a warning C4100: 'wadges' : unreferenced formal parameter relative to the line:
C++
void setwadges(int wadges){}

Fix it and initialize your variables, things should become clearer to you.
BTW what do you intend with: int hours[max_hours]; ?
cheers,
AR
   
Comments
EDITH GINGRAS 24-Nov-10 8:40am
   
what do you mean fix this I am not seeing what you mean the setup is the same as the others can you be more specific
Alain Rist 24-Nov-10 9:16am
   
I mean write your code so that the warning does not occur
EDITH GINGRAS 24-Nov-10 21:26pm
   
i am not getting an error it just does not give the correct answer example 5 hr at 5 per hour should be 25 dollars I get a random number 871etc and it does not matter what I do with that code it still does the same thi
Alain Rist 25-Nov-10 2:07am
   
As I told you in my answer first sentence, set your compiler warning level to maximum (for MSVC /W4 in Project->Settings->C++), compile and address all warnings.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900