没有得到正确的输出 [英] Not getting the right output

查看:68
本文介绍了没有得到正确的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可以编译,但是我得到错误的输出ex(5小时6/hr应该读30,但是我没有得到687 -----的答案,我将如何解决此问题以使其正常工作


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;
}

推荐答案

第一个显而易见的事情是setnumhours()不执行任何操作(如果小时arg有效).解决该问题,然后看看接下来会发生什么.
The first obvious thing is that setnumhours() does nothing (if the hours arg is valid). Fix that and see what happens next.


如果我以最高警告级别/W4 编译您的代码(应该始终这样做),则会得到一个警告C4100:"wadges":相对于该行的未引用形式参数:
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:
void setwadges(int wadges){}


修复它并初始化变量,事情对您来说应该更清楚了.
顺便说一句,您打算做什么:int hours[max_hours];?
欢呼声,
AR


Fix it and initialize your variables, things should become clearer to you.
BTW what do you intend with: int hours[max_hours]; ?
cheers,
AR


这篇关于没有得到正确的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆