Hello, I've recently started to learn C++ and I've come across an error when trying to run my programs, I am using Microsoft Visual C++ 2008, whenever I try to debug/run my program, it comes up with this code:
The program '[3264] CPP.exe: Native' has exited with code 0 (0x0).
I am asking for your help as I have not an idea what this code means? And how can I fix it so my programs run, thankyou.
@xtremerocker system("pause") causes ugly output on the screen and there're more reasons to avoid it. Try to use other solutions, such as cin.ignore(). There has been a big discussion about this toppic: http://www.cplusplus.com/forum/beginner/1988/
#include <iostream>
usingnamespace std;
void main(void)
{
int UsersAge = 0; //Variables can't have spaces, or numbers before them.
char Person = 'b'; // char= charatcer type specifier, with characters you use single quotations around them, with strings which means more then one character you use speech marks, with intergers you just leave them as they are.
cout << "What is your age?: " ;
cin >> UsersAge;
if (UsersAge >= 0 && UsersAge < = 4) // if= CPP Command (Coloured Blue), &&= and operator.
Person = 'b';
else //second part of if statement. so if it isn't a baby it will move to this part.
{
if (UsersAge >= 5 && UsersAge < = 20)
Person = 'y';
else // If you have one line of code under the if statement you don't need the braces "{ }".
{
if (UsersAge >= 21 && UsersAge < = 65)
Person = 'a';
else
{
if (UsersAge >= 66 && UsersAge < = 135)
Person = 'o' ;
else
Person = 'x';
}
}
}
if (Person == 'b')
{
cout << "Hello there, you are a baby- Because you are " << UsersAge << " years old" << endl ;
else
{
if (Person == 'y')
cout << "Hello there, you are a teenager- Because you are " << UsersAge << " years old" << endl ;
else
{
if (Person == 'a')
cout << "Hello there, you are a Adult- Because you are " << UsersAge << " years old" << endl ;
else
{
if (Person == 'o')
cout << "Hello there, you are a Old Person- Because you are " << UsersAge << " years old" << endl ;
else
{
if (Person == 'x')
cout << "I think you are lying because you are not " << UsersAge << " years old" << endl ;
}
}
}
}
}
// When you have a diagonal "if" it's called cascading.
}
There's my code, showing me where I would have to put these other solutions will be appreciated.
#include <iostream>
usingnamespace std;
void main(void)
{
int UsersAge = 0; //Variables can't have spaces, or numbers before them.
char Person = 'b'; // char= charatcer type specifier, with characters you use single quotations around them, with strings which means more then one character you use speech marks, with intergers you just leave them as they are.
cout << "What is your age?: " ;
cin >> UsersAge;
if (UsersAge >= 0 && UsersAge <= 4) // if= CPP Command (Coloured Blue), &&= and operator.
Person = 'b';
else //second part of if statement. so if it isn't a baby it will move to this part.
{
if (UsersAge >= 5 && UsersAge <= 20)
Person = 'y';
else // If you have one line of code under the if statement you don't need the braces "{ }".
{
if (UsersAge >= 21 && UsersAge <= 65)
Person = 'a';
else
{
if (UsersAge >= 66 && UsersAge <= 135)
Person = 'o' ;
else
Person = 'x';
}
}
}
if (Person == 'b')
cout << "Hello there, you are a baby- Because you are " << UsersAge << " years old" << endl ;
elseif (Person == 'y')
cout << "Hello there, you are a teenager- Because you are " << UsersAge << " years old" << endl ;
elseif (Person == 'a')
cout << "Hello there, you are a Adult- Because you are " << UsersAge << " years old" << endl ;
elseif (Person == 'o')
cout << "Hello there, you are a Old Person- Because you are " << UsersAge << " years old" << endl ;
elseif (Person == 'x')
cout << "I think you are lying because you are not " << UsersAge << " years old" << endl ;
//
// See: http://www.cplusplus.com/forum/beginner/1988/
system("PAUSE");
return 0;
}
Well when I press debug (F5) it opens in a flash and then dissappears as explained on the other thread, but I can't seem to get any of the codes that were given working.
Did you ever got any program running? I guess you're using VS and I'm not familiair with that compiler, but my guess is that you're not running your program, but the debugger, wich will close immidiatly because there arent any bugs. Did you compile the program? Can you find a button with "compile&run" or "run"?
(The program asks for input so it shouldnt blink without system("pause") either)