gpt4 book ai didi

如果不符合条件,C++ 创建数据输入循环

转载 作者:行者123 更新时间:2023-11-28 02:43:14 25 4
gpt4 key购买 nike

好久没编程了,我的问题如下。

我希望创建一个循环,如果输入的工资率不正确,该循环将返回到入口点。如果它不符合标准,我希望它打印出错误通知,否则转到您已满足标准。我还收到有关字符串 Laborer 的数据类型的错误,因为未定义。 IntelliSense:标识符“Laborer”未定义。我一直在努力解决这个问题,如下所示。任何方向将不胜感激。

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

最佳答案

您不能将未知变量“Laborer”分配给整数。看你的目标..我认为您在这里需要做的是将 int eel = Laborer; 更改为 string eel = "Laborer";

关于如果不符合条件,C++ 创建数据输入循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25237514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com