C2260未声明的标识符

时间:2016-04-30 22:44:20

标签: visual-c++

我收到错误amOrPm未声明的标识符有什么帮助吗?我尝试了很多东西,我确信它很简单。

男孩肯定会问我很多细节,我希望我能为每个人解释清楚。

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>


using namespace std;

// Declare constants
void input(int&hrs, int&mins, int&amOrPm);
int covert(int hrs, int amOrPm);
void outputStime(int hrs, int mins,int amOrPm);
void outputMtime(int hrs, int mins);

 int main()
{
// Declare variables below here
int hrs = 0, mins = 0, amOrPm = 0;
char choice;

cout << setiosflags(ios::fixed | ios::showpoint);

do 
{
    input (hrs, mins, amOrPm);
    covert(hrs, amOrpm);
    outputStime (hrs, mins, amOrPm);
    outputMtime (hrs,mins);

} while (choice != 'q' && choice != 'Q');

return 0;
}

void input(int&hrs, int&mins, int&amOrPm)
{
cout << "Enter The Hour: ";
cin >> hrs;

cout << "Enter The Minutes: ";
cin >> mins;

cout << "Enter 1 AM or 2 for PM: ";
cin >> amOrPm;

}

int convert(int hrs, int amOrPm)
{

    while (amOrPm = 2)
    {
        if (hrs >= 1)
        {
            hrs = hrs + 12;
            return hrs;
        }
        else
        {
            return hrs;
        }
    }
    while (amOrPm = 1)
    {
        if (hrs <= 11)
        {
            return hrs;
        }
        else
        {
            hrs = hrs - 12;

            return hrs;
        }
    }
}

 void outputStime(int hrs, int mins, int amOrPm)
{
    cout << " Standard time is: " << hrs << ":" << mins << amOrPm <<    endl;
}

void outputMtime(int hrs, int mins, int amOrPm)
{
    cout << " Standard time is: " << hrs << ":" << mins << endl;
}

1 个答案:

答案 0 :(得分:0)

covert(hrs, amOrpm);

应该是

convert(hrs, amOrPm);

此外,

while (amOrPm = 2)

while (amOrPm = 1)

应该是

while (amOrPm == 2)
while (amOrPm == 1)

一个等号表示赋值,您将amOrPm设置为2或1.两个等号(==)是比较,您将amOrPm与2或1进行比较。

int covert(int hrs, int amOrPm);

应该是

int convert(int hrs, int amOrPm);

为了匹配程序结束时的函数实现。