c++为不符合条件的数据输入创建循环

C++ creating a loop for data entry if does not meet criteria

本文关键字:输入 创建 循环 数据 不符合 条件 c++      更新时间:2023-10-16

我已经很长时间没有编程了,我的问题如下:

我希望创建一个循环,如果输入了不正确的工资率,将返回到入口点。我想让它打印出错误通知,如果它不符合标准,否则去你已经符合标准。我也得到了一个错误的数据类型为字符串劳动者没有被定义。智能感知:标识符"劳动者"未定义。我一直在努力工作,如下所示。如有任何指导,不胜感激。

#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 <<"ntt Enter Allowable Pay Rate For The Employee Position."<<endl;
        cout <<"nntt =====================================================";
        cout <<"ntt The Allowable Pay Rate Is: 20.00 to 49.99 per hour."<<endl;
        cout <<"nntt =====================================================";
        cout <<"ntt Enter Correct Pay Rate For The Position of "<<eel <<": ";
        cin >> hpr;
        cout <<"nntt =====================================================";
        if (hpr < 20.00 || hpr >49.99){
        {
            cout<<"nntt XX ERROR! ERROR! XX";
            cout<<"nntt YOU HAVE ENTERED AN INCORRECT PAY RATE FOR THE POSITION";
            cout<<"nntt PLEASE RE-ENTER THE CORRECT RATE FOR THE POSITION";
        }
            if (hpr >= 20  &&  hpr <= 49.99)
            {
                cout<<"nntt =========================================================";
                cout<<"ntt You Entered a Correct Pay Rate for the Position of "<< eel <<endl;
                cout<<"ntt Employee Hourly Payroll Rate Is: "<<hpr <<endl;
                cout<<"nntt =========================================================";
            }
            pause();          //To stop program to see if the loop is correct
        }
}

不能将未知变量"劳动者"赋值给整数。从你的目标来看…我认为这里需要做的是将int eel = Laborer;改为string eel = "Laborer";