-7
#include "iostream"
using namespace std;

int main()
{
int a,d,D,c,C,b,B,r,R;
char f,y,Y,n,N;

cout << "Press D - d, for dog,C -c for cat, B - b, for bird or R - r for Reptile:";
cin >> a;

if (a == d || a == D || a == c || a == C || a == b || a == B || a == r || a == R);

        if (a == d || a == D || a == c || a == C)

                if (a == d || a == D )
                 cout << "Is it neutered(Y/N)";
        cin >> f;
        if (f == Y || f == y)
                cout << "50 Euros.";
        else if (f == n || f == N)
                cout << "80 Euros.";

        if (a == c || a == C )
                cout << "Is it neutered(Y/N)";
        cin >> f;
        if (f == Y || f == y)
                cout << "40 Euros.";
        else if (f == n || f == N)
                cout << "60 Euros.";
        if (a == r || a == R || a == B || a == b)
                cout <<"10 Euros.";

if (a != d && a != D && a != c && a != C && a != b && a != B && a != r && a != R)
                cout << "Error!";

        system("pause");


        return 0;}

我得到的错误:

...\12b.cpp(21): warning C4390: ';' : empty controlled statement found; is this the intent?
...\12b.cpp(20): error C4700: uninitialized local variable 'd' used
...\12b.cpp(20): error C4700: uninitialized local variable 'D' used
...\12b.cpp(20): error C4700: uninitialized local variable 'c' used
...\12b.cpp(20): error C4700: uninitialized local variable 'C' used
...\12b.cpp(20): error C4700: uninitialized local variable 'b' used
...\12b.cpp(20): error C4700: uninitialized local variable 'B' used
...\12b.cpp(20): error C4700: uninitialized local variable 'r' used
...\12b.cpp(20): error C4700: uninitialized local variable 'R' used
...\12b.cpp(25): error C4700: uninitialized local variable 'Y' used
...\12b.cpp(25): error C4700: uninitialized local variable 'y' used
...\12b.cpp(27): error C4700: uninitialized local variable 'n' used
...\12b.cpp(27): error C4700: uninitialized local variable 'N' used

为什么我会收到此错误?我不明白??

4

2 回答 2

3

好的,让我们让这段代码更容易一些。我认为你打算做的是这样的:

char selection;
cout << (as before)
cin >> selection;

selection = tolower(selection);

switch(selection) {
case 'd':
   // stuff for dogs here
   break;
case 'c':
   // stuff for cats
   break;
// etc.
default:
   // error case
}

正确的?

于 2013-04-06T21:43:11.613 回答
2

我认为很明显,而不是

if (a == d || ...

你真的想要

if (a == 'd' || ...

即您想将变量a与字符进行比较'd'。你已经多次犯了同样的错误,所以把它们都修好,看看还剩下什么错误。

此外,您错误地声明aintwhen is should be a char. 你说对了,f但不是a出于某种原因。

于 2013-04-06T21:44:01.297 回答