+ 1

hi. I have a program and I want it to close when i write a specific word and if we input another word it doesn't close. How can I do it?

#include <iostream> using namespace std; int main() { int a; cout<<"cati bani aveti? \n"; cin>>a; cout<<a<<endl; // aici e prima intrebare int b; cout<<"cat sunteti dispusi sa dati pe o shaorma? \n"; cin>>b; cout<<b<<endl; // a doua intrebare int c=a/b; cout<<"va puteti lua \n"<<c<<endl; return 0; } // primul meu program in c++

31st Jul 2016, 11:58 PM
Alex
1 Odpowiedź
+ 2
#include <string> string str; int strLgth; getline(cin, str); strLgth = str.length(); for (int i = 0; i < strLgth; i++) str.at(i) = tolower(str.at(i)); if (str == "stop") return 0; EDIT: The problem with this is that if the user enters "Stop", it would not work because of the capital letter. To tackle this, you can build a for loop to turn the entire string to lower case. I have added this.
1st Aug 2016, 9:54 AM
Cohen Creber
Cohen Creber - avatar