c++ - My program won't print anything... -
so i'm working on building calculator mimics ones use everyday. have shown logic within function. when had cout lines (deleted, not shown anymore) see if "y" being correctly stores, , 2 variables, finalnum1 & 2, working, when going back, trying add new cout lines, nothing prints. if there more issues, feel free point them out, code unfinished, main concern nothing printing, understand code still needs work. if can that'd appreciated!
int calculator::calculate() { if (userinput[0] != 'q' || 'q') // checks user input "quit" or "quit" { int stringsize; std::cin >> userinput; // user input stringsize = userinput.length(); int y = 0; while (y < stringsize) { if (isdigit(userinput[y])) {} else { posi = y; } y++; } first = userinput.substr(0,posi); second = userinput.substr(posi+1,y); finalnum1 = std::stoi(first); // sigbart error finalnum2 = std::stoi(second); std::cout << finalnum1 + finalnum2; // won't print switch (userinput[posi]) { case '+': std::cout << finalnum1 + finalnum2; break; case '-': std::cout << finalnum1 - finalnum2; break; case '*': std::cout << finalnum1 * finalnum2; break; case '/': std::cout << finalnum1 / finalnum2; break; case '%': std::cout << finalnum1 % finalnum2; break; } } else std::cout << "goodbye"; return 0; }
for printing integer easier if cast them string.
using namespace std; float tmp = finalnumber1 + finalnumber2; string out = to_string(tmp); cout << tmp << endl;
then thing. should use for
instead of while
.
Comments
Post a Comment