Run-Time Check Failure #3 - The variable 'number' is being used without being initialized.

Hello, I'm very new to programming, as I just started a couple of weeks ago,
and I am doing some excersises, but when I try to run the program, I get the error displayed in the title of this post.

#include <iostream>
#include <string>

using namespace std;

int main()
{
int number;

cout << "Please enter an integer between 0 and 35." << endl;

if (number < 0)
{
cout << "Please enter an integer between 0 and 35." << endl;
}

else if (number > 35)
{
cout << "Please enter an integer between 0 and 35." << endl;
}
else if (number >= 0 && number <= 9)
{
cout << number << endl;
}
else if (number >= 10 && number <= 35)
{
cout << static_cast<char> (number) << endl;

}
return 0;



}

These basic errors affect some experienced programmers and therefore, variable initialization is one of the helpful steps taken to avoid this.

Actually, the problem is because you did not give number a value, and you are comparing with it. I think you missed the cin>>number; statement.
Last edited on
I'm an idiot. Thanks a lot, I didn't even realize.
Topic archived. No new replies allowed.