I am a beginner in C++ and I was doing a do/while loop exercise and I am having trouble with it recognising the condition let alone it not looping properly. Can you guys give me a good foundation on how a simple problem like this is solved? I want to try and use a string to fulfill the condition of the do/while loop.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
double mean = 0;
string continuer;
do
{
cout << "Do you want to proceed?" << endl;
getline (cin, continuer);
cout << "something" << endl;
cin >> mean;
}
while (continuer == "Y" || continuer == "y");
return 0;
}
What I gather from your question and comment, you want to iterate through the loop at user’s will.
You just want a
charvariable for that, like this.This do-while loop will execute at least one time, because the condition gets checked at the end of the loop execution. So even if the user does not press Y when asked the first time, this loop would have been executed once. After that, it will go on as long as the condition is fulfilled.
Learn more about the do-while loop here.
http://www.cplusplus.com/doc/tutorial/control/