自从我编程以来已经有很长时间了,我的问题如下。

我希望创建一个循环,如果输入的工资率不正确,该循环将返回到入口点。如果它不符合条件,我希望它打印出错误通知,否则转到符合条件的位置。我也收到字符串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++ - 如果不符合条件,C++将为数据输入创建循环,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25237514/

10-10 14:19