0

C++ [9999] Question

#include <iostream> #include <string> using namespace std; int main () { int userInput; bool trueValue = true; cout << "Welcome to the Calculator that can only count up to 4 digits." << endl; cout << "If you would like to view the current sum, please type [TOTAL]" << endl; cout << "Enter 9999 to [EXIT]." << endl; while ((userInput < 9999 || userInput == "TOTAL") && trueValue) { if (userInput == "TOTAL") { cout << userInput << endl; } else { cout << "Please enter a number:" << endl; cin >> userInput; if (userInput == 9999) { trueValue = false; } else { trueValue = true; userInput += userInput; } } return 0; } } How would I be able to compare both a integer and string for my condition, I'm thinking of parsing the input but I'm not sure how.

21st Feb 2018, 6:27 PM
Winson Dieu
Winson Dieu - avatar
1 Answer
+ 1
If i understood your question you want to combine strings? just parse your input into strings instead of integer, though that will cause the adding of numbers to not work(1+1=11). to change that you should create an if statement that will check if the input is numbers or chars. if its numbers than consider this as a number, if its a char consider it as a string. regrading syntax, i cannot help you with that with C. wait for help from an other user.
21st Feb 2018, 6:35 PM
Tomer Sim
Tomer Sim - avatar