Undeclared Identifer

Good Morning!

I am new to C++ and very frustrated... I am working on an assignment and keep receiving the error Undeclared Identifier, I am not sure why it is not seeing my fruit or type. If anybody can give me some input and let me know where I am going wrong I would greatly appreciate it. Thanks

#include <iostream>
#include <string>

using namespace std;
int main()
{
string fruit;
string type;

cout << "Apples, Oranges or Pears? ";
cin >> fruit;
if (fruit == Apples);
cout << "Golden Delicious, Granny Smith, or McIntosh? ";
else if (fruit == Oranges);
cout << "Valencia, Blood or Navel ";
else if (fruit == Pears);
cout << "Bartlett, Bosc or Comice ";
else cout << "Next time please enter one of the fruits requested!" << endl;
cin >> type;
cout << "You have selected " << type << " " << fruit << endl;
}

ERRORS are listed below:

Error 1 error C2065: 'String' : undeclared identifier assign14.cpp 15
Error 2 error C2146: syntax error : missing ';' before identifier 'fruit' assign14.cpp 15
Error 3 error C2065: 'fruit' : undeclared identifier assign14.cpp 15
Error 4 error C2065: 'String' : undeclared identifier assign14.cpp 16
Error 5 error C2146: syntax error : missing ';' before identifier 'type' assign14.cpp 16
Error 6 error C2065: 'type' : undeclared identifier assign14.cpp 16
Error 7 error C2065: 'fruit' : undeclared identifier assign14.cpp 19
Error 8 error C2065: 'fruit' : undeclared identifier assign14.cpp 20
Error 9 error C2065: 'fruit' : undeclared identifier assign14.cpp 21
Error 10 error C2065: 'fruit' : undeclared identifier assign14.cpp 22
Error 11 error C2065: 'type' : undeclared identifier assign14.cpp 24
Error 12 error C2065: 'type' : undeclared identifier assign14.cpp 25
Error 13 error C2065: 'fruit' : undeclared identifier assign14.cpp 25
The errors you posted don't match the code you posted.

Make sure you have 'string' (with a lowercase s) like you do in your post. From your errors, it looks like you're capitalizing the S in your program (bad).

Here are some other errors:

-) when you want to compare a string to a string literal (ie: see if fruit contains the word Apples), you need to put quotes around the literal.

Example:

1
2
3
4
5
if(fruit == Apples)  // this compares the variable 'fruit' to the variable 'Apples'
  // note you don't have a variable named Apples, so this is an error.

// if you want to see if the variable fruit contains the word Apples, put Apples in quotes:
if(fruit == "Apples")


-) don't put semicolons after if statements. That marks the end of the if statement.

1
2
3
4
5
if(something);  // bad - shouldn't have a semicolon here
  Dosomething;

if(something)   // good
  Dosomething;
Thanks... I will try this and let you know...
Topic archived. No new replies allowed.