+ 1

how to create loops with strings in c++ ?

how can i create infinite loops for asking question and if someone replies with dumb text then ask them to answer in a specific format...... for example i ask :- are you happy with the job and there answer have to be yes and no but they reply with "no, i'm not" then the statement should come please answer in yes and no format......

18th Aug 2017, 8:21 AM
Som Harsh
Som Harsh - avatar
2 Answers
+ 2
//first make a array or text file that contain the quation than do a while loop until the array or the file come to the end. //make a variable that contain the answar and than make a if stentment that check if the answar is what you want or not. //if yes continue with the array or read from the file if not do a sun while loop until he input the right answar //dont forgget to do a exit variable if the client want to exit in the middle of the program i know the sorce code cuz i do stuff like this so i give you the idea and leave the rest for you
18th Aug 2017, 8:45 AM
Dor Nachemani
Dor Nachemani - avatar
+ 7
#include <string> // std::string, std::toupper .... std::string choice = ""; do { cout << "Are you happy with the job? (yes/no)"; cin >> choice; for ( size_t n = 0; n < choice.length(); ++n) choice[n] = std::toupper(choice[n]); if (choice == "YES" || choice == "NO") break; } while (true);
18th Aug 2017, 9:03 AM
Babak
Babak - avatar