If statement with a char
Apr 24, 2015 at 7:32am Apr 24, 2015 at 7:32am UTC
how can i make my program ask for a char("Q") to quit/initialize
the if statement?
i get an c3867 error when i run it. but i can't see what i do wrong
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
Body of program
*/
#include <iostream>
#include <string>
#include "headerRpg.h"
using namespace std;
char a;
roomOne::roomOne()
{
cout << "apples are cool" << endl;
cin >> a;
cin.ignore();
if (a == 'Q' )
{
cout << "quitting...." << endl;
cin.ignore;
}
}
Thanks for the help
Apr 24, 2015 at 7:56am Apr 24, 2015 at 7:56am UTC
On line 25: Add the parentheses: cin.ignore() ;
Apr 24, 2015 at 9:29am Apr 24, 2015 at 9:29am UTC
You can use the exit() function defined in stdlib.h .
1 2 3 4 5 6 7 8 9 10 11 12 13
#include<iostream>
//other includes.....
#include<stdlib>
using namespace std;
//passing to the main point
if (a=='Q' ||a=='q' )
{
cout<<"Quitting...." <<endl;
exit(0);
}
You have to specify the '0' in the exit() function by the way.
Topic archived. No new replies allowed.