Well in CPR (Computer Programming and Repair) we're doing a simple program and it includes this.........and I need some help in finding out with what's wrong with it because every time you input the number and it closes you out immediately.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int age;
cout << "How old are you?" <<endl;
cin >> age;
cout << "Holy JEVUS you are " <<age<< " years old!" <<endl;
return 0;
}
On another note, just so your aware, the cin is in the wrong place. At least if you want it to look nicer. I mean it works, but it is bad practice to put the input on the next line. It should be immediately after the ? ( question ).
Although, if you knew this already, then no problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int age;
cout << "How old are you? "; // Did you notice I took out <<endl
cin >> age;
cout << "Holy JEVUS you are " <<age<< " years old!" <<endl;
return 0;
}
The only other problem I could see is making sure that ONLY numbers will be inputted. It will error out if you try to type in a letter or some other character other then a number.
Yeah, grax is right, your program is doing exacly what you told it to, you just forgot to tell it to wait for you te read what it wrote
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
This is the header file that has the function that
will wait forus to read the text on the console
*/
#include <cstdlib>// YOU NEED TO DO THIS
#include <iostream>
#include <string>
usingnamespace std;
int main() {
int age;
cout << "How old are you? ";
cin >> age;
cout << "Wow! You are " << age << " years old!" << endl;
system("pause");// AND THIS
return 0;
}
Using system("pause") is a bad habit to get into. Don't worry about why right now, has to do with security and stability. Depending on the IDE you are using, there should be an option to run without debugging, that will leave your window open. Or you could just add a cin << something at the end of your program, that will wait for some input before it closes.
I realize the implications that system("pause") brings, I was simply helping the guy out, and as a newbie he doesn't need to worry about anything like that right now
Dev-C++ is just as efficient and safe as any other C++ development environment.
If you're referring to the recent continuation of Dev-C++ (V4.9.9.3 and above, found over here: http://orwellengine.blogspot.com/ ) then it is much improved and comes with a modern compiler.
If you mean the version found over at Bloodshed, then your statement is demonstrably false and dangerous to newcomers.
Unfortunately, a search for Dev-C++ by an enthusiastic newcomer tends to turn up the bad version first.