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

时间:2014-08-11 07:03:41

标签: c++

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

如果输入的付款率不正确,我希望创建一个返回入口点的循环。我希望它打印出错误通知,如果它不符合标准,否则转到你已经符合标准。我也在字符串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
        }
}

1 个答案:

答案 0 :(得分:2)

您不能将未知变量'Laborer'分配给整数。通过你的目标看起来.. 我认为您需要做的是将int eel = Laborer;更改为string eel = "Laborer";