can anyone tell me please, how to stop this program.
It should finish for q and give the result for c.
#include<iostream>
using namespace std;
int main()
{
char ch;
cout<<"press c to continue or q to quit ";
cin>>ch;
do{
cout<<"hello world 1";
cout<<endl;
}
while(ch=='c');
return 0;
}
#include<iostream>
usingnamespace std;
int main()
{
char ch;
do{
cout<<"press c to continue or q to quit ";
cin>>ch;
cout<<"hello world 1";
cout<<endl;
}
while(ch=='c');
return 0;
}
I think your problem is when you type in 'q', the program outputs "Hello world 1" and then quits, while you want it to quit immediately after you type in 'q', right?
If this is the case, you should modify your code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<iostream>
usingnamespace std;
int main()
{
char ch;
do
{
cout<<"hello world 1";
cout<<endl;
cout<<"press c to continue or q to quit ";
cin>>ch; //ask for input just before checking the condition
}
while(ch=='c');
return 0;
}