Hey so I came back to c++ earlier, and while I'm not an amazing coder I figured I could do the practices easily for some warm ups to get used to the language again. so I got the calc one and did it, and from what I can see the code I have is the same as the solution, just lacking the "using namespace std" because I remember seeing people say that was a bad habit to have, though I did use "std::???" appropriately.
But when I run the code and try to use something, it starts spamming the console with the normal message, and I can't figure out why, I'm sure its something really simple and basic that I'm missing, but could you guys lend me a hand?
Code:#include <iostream> int multiply(int x, int y) { return x*y; } int divide(int x, int y) { return x/y; } int add(int x, int y) { return x+y; } int subtract(int x, int y) { return x-y; } int main() { char op='c'; int x, y; while(op!='e') { std::cout<< "What operation would you like to perform: add(+), subtract(-), divide(/), multiply(*), [e]xit?"; std::cin>>op; switch(op) { case '+': std::cin>>x; std::cin>>y; std::cin>>y; std::cout<< x << "+" << y << "=" << add(x, y) <<std::endl; break; case '-': std::cin>>x; std::cin>>y; std::cout<< x << "-" << y << "=" << subtract(x, y) <<std::endl; break; case '/': std::cin>>x; std::cin>>y; std::cout<< x << "/" << y << "=" << divide(x, y) <<std::endl; break; case '*': std::cin>>x; std::cin>>y; std::cout<< x << "*" << y << "=" << multiply(x, y) <<std::endl; break; case 'e': return 0; default: std::cout<< "Sorry, try again" <<std::endl; } } return 0; }



LinkBack URL
About LinkBacks



