Emergency help error issue!

I have two diverse versions of Microsoft Visual Studio, one that is 2010 Ultimate, and the other that is 2010 Express Edition. So just the other day I was debugging on my C++ 2010 Ultimate in 32Console APP. I was practicing booleans, if, and else statements. I had absolutely no problems displayed what so ever, my debugging came out with no issues. Today I debug and I get an error that says Run-Time Check Failure #3 - The variable 'validNumber' is being used without being initialized., and it gives me the option to "BREAK" or "CONTINUE". So I said to myself either I am doing something wrong or 'it must be the program its self?' then I decided to use Visual studio 2010 express edition, and yet I get the same issue. Here's the issue that I did not have with the other day using this code:

#include "stdafx.h"
#include <iostream>

using namespace std;

int main(void)
{
system("color 0e");

int x = 0;
int y = 0;

bool validNumber;
while (validNumber==false)

{
cout<<"Type a number inbetween 5 through 10"<<endl;
cin>>x;
cout<<"You Entered: "<<x<<endl<<endl;

if ((x<5)||(x>10))
{
cout<<"You have entered an invalid number that is out of range"<<endl
<<"Please try again and enter within' the range"<<endl;
}
else validNumber=true;
}
cout<<"Thank you for participating"<<endl;

system("Pause");
return 0;
}

//it tells me The variable 'validNumber' is being used without being initialized.
//How is this so if just the other day I was writing this exact code and it came perfect?
//I bet if you type in that exact code you might not have no problems...

Last edited on
You'll need to be more specific about what you're running and what you see. But do not reinstall your OS.
Um... Post some code (and don't reinstall your OS...?)
Well, the code is bad (you are using variables without assigning values to them) so if it wasn't working before, it is now.

1
2
bool validNumber;
while (validNumber==false)


You test validNumber, but it could be anything at that point. You never assigned a value to it.
Last edited on
It was working before though... I never had a run time failure check stating 'validNumber' is being used without being initialized. So my question is, why is it that it was working before, and now all of a sudden the next day... it gives me a failure check?
If the code is bad then, how would I assign a value from your suggestion? if you can show me an example? it just scares me because im thinking something was deleted in the programs .dll's or something lol? so idk...
Unless you post your code and possibly your input, the best we can do is speculate on what's wrong.
I did post the code up there ^
So I have to assign a value for valid?
how do I assign a value for valid and where? is it suppose to be where the header files are at?

Last edited on
See Moschops's reply above.
Last edited on
So I have to assign a value for valid?


Here is how to assign a value. If you really couldn't work this out, I think you need to go back to basics and start learning again at the very beginning. It seems very odd, because you wrote this code that assigns the value 0 to int x and int y.

1
2
int x = 0;
int y = 0;


I'm going to use an int in my example, but it could be a bool, or a double, or any other type.

1
2
int x; // x is now created but has no value assigned to it. It could be anything
x = 7; // now the value 7 has been assigned. x is seven. 


Here is another way to do the same thing.

int x = 7;

Here's a bool example, in which I assign the value false to a bool named validNumber.

bool validNumber = false;

Here's another way to do the same thing.

1
2
3
4
bool validNumber;
// If I use validNumber on this line, it could be any random value.
validNumber = false;
// Now, if I use validNumber on this line, it definitely has a known value  

Last edited on
Topic archived. No new replies allowed.