Ok I've posted a couple of posts before regarding OpenGL stuff, but I realized I'll be better off learning c++ first (yeah!). So I started reading through some tutorials and already got the hang of if statements, variables, funcitons, and loops. So I decided that I could make a little text game to test myself using all those things I learned. The game is very simplistic it just returns certain couts depending on input. I got it all working except for when I inserted the else statement. When i run the program it gives me a Run-Check 3 error.

Here's the code for the program, also it uses some spanish bad words i hope you guys dont understand em hehe my apologies to the ones that does, anyway here it is:

#include <iostream>

int main () {
do {
	int (b);
	int (a);
	char ENTER, enter, Enter= a;
	std::cout<<"No apretes enter... \n";
	std::cin.ignore();
	std::cout<<"Te digo que no le des a ENTER \n";
	std::cin.ignore();
	std::cout<<"Puneta que no le des a ENTER no entiendes? Carajo \n";
	std::cin.ignore();
	std::cout<<"NO LE DES A ENTERN\nO################O\n ################ \nL################L\nE################E\n ################ \nD################D\nE################E\nS################S\n ################ \nA################A\n ################ \nE################E\nN################N\nT################T\nE################E\nR################R\nNO LE DES A ENTER\n";
	std::cin.ignore();
	std::cout<<"Ok, Marisconsin sigue dandole a ENTER para que tu veas\n";
	std::cin.ignore();
	std::cout<< "Sabes que comienzas a irritarme verdad? Eso no es nada bueno\n";
	std::cin.ignore();
	std::cout<<"Ok ya me canse, dale a ENTER todo lo que te de la gana, pero no lo escribas\n";
	std::cin>>(b);
	if (b=a){
		std::cout<<"Quieres joderme tanto que escribistes enter?";
	}
	else {
		std::cout<<"Muy bien sigue apretando ENTER pero no lo escribas";
	}

any input of what may be going wrong would be greatly apreciated

ps. i know the code looks a lil messy but as i havent finished it yet i havent put comments or organized it.

Thanks again,
Expora.

I'm using Visual Studio Express 2010 and in the debug it says:
"The variable 'a' is being used without being initialized"
I had it declared at the beginning so not sure what initialized means.

Initialization is when you set a variable equal to something for the first time. You're never actually setting your variable 'a' to any value, but in line 7, you're setting your 'Enter' variable equal to that 'a' variable.

Also, your if statement condition isn't going to work how I'm assuming you want it to. A single = is assignment, whereas double (==) is the is equal operator.

Ok so I changed it now the code runs perfectly but when it gets to the if statement it just exits. What I'm trying to do is when the program gets to if get the user input if the input is either ENTER, enter, or Enter run if else run else and loop it but i dont seem to figure that out. Again im only familiar with loops variables and if statements not sure if i need to know anything else. If someone could give an example that be great
Thanks again,
Expora

Try putting a WHILE{} inside your ELSE{} - Maybe this will solve your problem? Something along the lines of

if (...)
{
   ....
}
else
{
     while (a != Enter || ENTER || enter)
     {
         ....
         
         cout << "type enter to exit loop" << endl ;
         cin >> a ;
     }
}
}

modified my previous post quite a bit - may want to look over it again.

Uhmm nice I thought while was for loops going to try this. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.