本文介绍了错误1错误C4700:C ++中未初始化的本地变量“rate”和“hours”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是编程的初学者。我写一个C ++程序,用户将他们的工资率和工作时间,然后计算工资和工作时间然后显示它。我完成程序有两个错误,我试图修复,但我仍然不能弄清楚修复它。错误和我的代码如下。有人可以帮助我,告诉我如何解决?我使用的是MSVS Express 2013。
I am a beginner to programming. I'm writing a C++ program that a user will their pay rate and the hours worked, and then calculate the pay and hours worked then display it. I finish the program the there are two errors that I tried to fix but I still can't figure out to fix it. The errors and my code is below. Can someone help me and tell me how to fix? I'm using MSVS Express 2013.
错误:
Error 1 error C4700: uninitialized local variable 'hours'
Error 2 error C4700: uninitialized local variable 'rate'
( displayWeekly(rate,hours);
)错误
代码:
#include "stdafx.h"
#include<iostream>
using namespace std;
void displayWeekly(double rate, int hours);
double getRate();
int getHours();
int main()
{
double rate;
int hours;
displayWeekly(rate, hours);
double getRate();
int getHours();
rate = getRate();
hours = getHours();
system("pause");
return 0;
}
void displayWeekly(double rate, int hours)
{
double weekPay;
weekPay = rate * hours;
cout << "Weekly pay is " << weekPay << endl;
}
double getRate()
{
double rate;
cout << "Enter your Hourly rate in the Dollars and Cents = ";
cin >> rate;
return rate;
}
int getHours()
{
int time;
cout << "Please Enter in the Hours you worked" << endl;
cout << "You must Enter a whole Number = ";
cin >> time;
return time;
}
推荐答案
像这样:
int main()
{
double rate;
int hours;
//double getRate(); --> where do you think the return value is stored to?
//int getHours(); -->
rate = getRate();
hours = getHours();
displayWeekly(rate, hours); // --> has to go after you put values to rate & hours
system("pause");
return 0;
}
这篇关于错误1错误C4700:C ++中未初始化的本地变量“rate”和“hours”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!