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;
}
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;