I recently started learning c++ and wrote this code myself but something's off the loop break doesn't seem to terminate the program.
can someone take a look?
#include <iostream>
// input output
double add (double a,double b){
return a + b;
}
// add function
double subtract (double a,double b){
return a - b;
}
//subtract function
double multiply (double a,double b){
return a * b;
}
//multiply function
double divide (double a,double b){
if (b == 0){
return 0;
}
return a / b;
}
//divide function
int main(){
char option = ' ';
double a, b;
// main loop
std::cout<<"Choose an operation(+ - * / q)" <<std::endl;
while(option != 'q'){
std::cin>>option;
if(option == 'q'){
break;
}
// quit
std::cout<<"enter the first number" << std::endl;
std::cin>>a;
std::cout<<"enter the second number" << std::endl;
std::cin>>b;
//option
if(option == '+'){
std::cout<<add(a, b) << std::endl;
}
else if(option == '-'){
std::cout<<subtract(a, b) << std::endl;
}
else if(option == '*'){
std::cout<<multiply(a, b) << std::endl;
}
else if(option == '/'){
std::cout<<divide(a, b) << std::endl;
}
else{std::cout<<"invalide operation"<< std::endl;}
}
return 0;
//end
}
I refuse to seek claud's help. I'd be a snail cat