stuck with the cin object please

hi, below is my code:

#include <iostream>
using std::cout;
using std::endl;
using std::cin;

main()
{
int score = 0;
double distance = 1200.76;
char playAgain ='y';
bool shieldsUp = true;
short lives=3;
short aliensKilled = 10;
double engineTemp = 6572.89;

cout<<"\nscore: " << score <<endl;
cout<<"distance: " <<distance<<endl;
cout<<"playAgain: "<<playAgain<<endl;
cout<<"lives: " <<lives<<endl;
cout<<"aliensKilled: " <<aliensKilled<<endl;
cout<<"engineTemp: " <<engineTemp<<endl;

int fuel;

cout << "\nHow much fuel? ";
cin >> fuel;
cout << "fuel: " << fuel <<endl;

typedef unsigned short int ushort;
ushort bonus = 10;
cout<< "\nBonus: " <<bonus<<endl;

}

i understand that the cin object is an input object, so, i want to put a value into the variable called fuel, so ive put cin >> fuel;, but when i run the progam nothing happens, all that comes up is everything up the "how much fuel?", i tryed typing 50 in thinking i would put the value of 50 into the fuel variable, then when i press enter to input the value to fuel the program closes, how exactly do i input a value to a variable whilst the program is running????????
It sounds like your program is closing before you can read the output. Here, Duoas' solution from here:
http://www.cplusplus.com/forum/beginner/1988/

-Albatross
Last edited on
hmm, it works when i run from the batch file, but not when clickin on compile and run within Dev C++ as it closes when i type in and press enter, hmm
Topic archived. No new replies allowed.