[英]C++ creating a loop for data entry if does not meet criteria
It has been a long time since I have programmed and my problem is as follows. 自从我编程以来已经有很长时间了,我的问题如下。
I wish to create a loop that will return to the entry point if the incorrect pay rate is entered. 我希望创建一个循环,如果输入的工资率不正确,该循环将返回到入口点。 I want it to print out the error notice if it does no meet the criteria, otherwise go to the you have meet the criteria.
如果它不符合标准,我希望它打印出错误通知,否则转到符合标准的位置。 I am also getting an error on data type for the string Laborer as not being defines.
我也收到字符串Laborer的数据类型错误,因为未定义。 IntelliSense: identifier "Laborer" is undefined.
IntelliSense:标识符“ Laborer”未定义。 I have been trying to work it out as seen below.
我一直在努力解决问题,如下所示。 Any direction would be greatly appreciated.
任何方向将不胜感激。
#include "stdafx.h"
#include "stdlib.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cctype>
#include <conio.h>
#include <cstdlib>
#include <cstring>
using namespace std;
int eel;
int hpr;
int kbhit()
void pause()
{
cout << "Press any key to continue....";
while(1)
{
if(kbhit())
{
break;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int eel = Laborer;
int hpr = 0;
while (hpr < 20.00 || hpr >49.99)
{
cout <<"\n\t\t Enter Allowable Pay Rate For The Employee Position."<<endl;
cout <<"\n\n\t\t =====================================================";
cout <<"\n\t\t The Allowable Pay Rate Is: 20.00 to 49.99 per hour."<<endl;
cout <<"\n\n\t\t =====================================================";
cout <<"\n\t\t Enter Correct Pay Rate For The Position of "<<eel <<": ";
cin >> hpr;
cout <<"\n\n\t\t =====================================================";
if (hpr < 20.00 || hpr >49.99){
{
cout<<"\n\n\t\t XX ERROR! ERROR! XX";
cout<<"\n\n\t\t YOU HAVE ENTERED AN INCORRECT PAY RATE FOR THE POSITION";
cout<<"\n\n\t\t PLEASE RE-ENTER THE CORRECT RATE FOR THE POSITION";
}
if (hpr >= 20 && hpr <= 49.99)
{
cout<<"\n\n\t\t =========================================================";
cout<<"\n\t\t You Entered a Correct Pay Rate for the Position of "<< eel <<endl;
cout<<"\n\t\t Employee Hourly Payroll Rate Is: "<<hpr <<endl;
cout<<"\n\n\t\t =========================================================";
}
pause(); //To stop program to see if the loop is correct
}
}
You cannot assign an unknown variable 'Laborer' to an integer. 您不能将未知变量“ Laborer”分配给整数。 By the looks of your goal.. I think what you need to do here is change
int eel = Laborer;
从您的目标看。我认为您需要在这里做的是
int eel = Laborer;
to string eel = "Laborer";
string eel = "Laborer";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.