Help with loop statement
Mar 24, 2013 at 9:38pm UTC
Hi, I started programming c++ about a week ago and I have reached a stump in the road. Whenever I run the program in the decompiler it closed automatically. I tryed using system("pause"),cin.get(), and getch(),getche(); I use Notpad ++ and MinGW to work with and I learn off of cplusplus.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
short int StartingInt;
cout << "Start the number you want it to load at!" << endl;
cin >> StartingInt;
while (StartingInt > 0){
cout << StartingInt <<", " ;
--StartingInt;
}
cout << "It is done loading." << endl;
cout << "Test!" ;
getche();
return 0;
}
Mar 24, 2013 at 9:46pm UTC
You mean that you dont have a compiler?
Mar 24, 2013 at 9:48pm UTC
I mean everytime I compile it into a exe it closes when I use it
Mar 24, 2013 at 9:55pm UTC
How about this one
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# include <iostream>
# include <limits.h>
using namespace std;
int main()
{
short int StartingInt;
cout << "Start the number you want it to load at!" << endl;
cin >> StartingInt;
while (StartingInt > 0){
cout << StartingInt <<", " ;
--StartingInt;
}
cout << "It is done loading." << endl;
cout << "Test!" ;
cin.ignore();
cin.ignore(INT_MAX,'\n' );
return 0;
}
Mar 24, 2013 at 9:59pm UTC
Thanks, it worked!
Topic archived. No new replies allowed.