When I complie it says, "error C2065: 'Favorite_Number1' : undeclared identifier" what can i do to fix this?
//Favorite_Number
//Include the iostream library
#include <iostream>
//Use the standard namespace
using namespace std;
void main ( )
{
// Give instructions
cout << "Can you guess my favorite number?" << endl;
cin >> Favorite_Number1;
if (Favorite_Number1 == 6)
{
// Print text
cout << "Yay That's Correct!" << endl;
}
system ("PAUSE");
}
Copyright © 2024 Q2A.MX - All rights reserved.
Answers & Comments
Lets analyze the error you are getting.
"error C2065: 'Favorite_Number1' : undeclared identifier"
"error (The compiler detected an error and can not compile the code)
C2065: (If you look up this number it will describe the type of error found)
'Favorite_Number1' : (This is what it had a problem with)
undeclared identifier" (And this is the problem)
So it is saying Favorite_Number1 is undeclared.
When you look at your code you will see that you use Favorite_Number1 in your code, BUT what IS Favorite_Number1? Looking at your code, it is not defined!
Bottom line, add this in your main:
int Favorite_Number1;
NOW Favorite_Number1 is defined as an integer.
It's int main not void main...
you did not declare Favorite_Number1 before you used it like
int Favorite_Number1;
you should use system("PAUSE") without including Windows.h
and you didn't return 0; (probably because you used void main which is not correct for the standard)