example of problem:: 5+5 = 10 and then the user used other operate 5 - 2 = 3 the program will print out
the total of 5 -2 = 3 and the sum is 13 my problem is that the functions can't return the value TOTAL.. Sorry but my characters are limit i can reply if that helps you!!! Thank you !!!
#include <iostream>
#include<iostream>
#include<string>
#include<iomanip>
#include<stdio.h>
#include <cmath>
#include <pthread.h>
#include <unistd.h>
usingnamespace std;
void quit()
{
char option2;
double val = 5.9;
cout << "Are you sure you want to quit from the program??(Y/N): "<<endl;
cin >> option2;
if ((option2=='Y') || (option2=='y'))
{
cout << "GoodBye!!! C ya later!!!.. "<<endl;
}
elseif ((option2=='N') || (option2=='n'))
{
cout <<"You will now return to main menu!!!"<<endl;
}
elseif ((option2!='y') || (option2!='Y') || (option2!='n') || (option2!='N'))
cout << "Error input.. The program will exit in 5 seconds..."<<endl;
sleep ( val );
}
double addition()
{
double num1,num2;
double total;
cout << "Addition"<<endl;
cout << "********"<<endl;
cout << "Enter 2 numbers to calculate: "<<endl;
cin >> num1>>num2;
total = num1 + num2;
total += total;
cout <<"The total sum of "<<num1<<" + "<<num2<<" = ";
return (total);
}
double subtraction()
{
double num1,num2;
double total;
cout <<"Subtraction"<<endl;
cout <<"***********"<<endl;
cout <<"Enter 2 number to calculate: "<<endl;
cin >> num1>>num2;
total = num1 - num2;
total +=total;
cout <<"The subtraction of "<<num1<<' - '<<num2<<" = ";
return (total);
}
double multiplication()
{
double num1,num2;
double total;
cout <<"Multiplication"<<endl;
cout <<"***********"<<endl;
cout <<"Enter 2 number to calculate: "<<endl;
cin >> num1>>num2;
total = num1 * num2;
total += total;
cout << "The total multiplication of "<<num1<<" * "<<num2<<" = ";
return (total);
}
double division()
{
double num1,num2;
double total;
cout <<"Division"<<endl;
cout <<"***********"<<endl;
cout <<"Enter 2 number to calculate: "<<endl;
cin >> num1>>num2;
total = num1 / num2;
total += total;
cout << "The total division of "<<num1<<" / "<<num2<<" = ";
return (total);
}
double sum_squared()
{
double num1,num2;
double total = 0.0;
double displayedVal;
displayedVal = 0.0;
cout <<"Sum squared"<<endl;
cout <<"***********"<<endl;
cout <<"Enter 2 number to calculate: "<<endl;
cin >> num1>>num2;
displayedVal = pow (num1, num2);
cout << "The total sum squared of "<<num1<<" ^ "<<num2<<" is ";
total += displayedVal;
return (total);
}
double less_than_relation()
{
double num1,num2;
double total;
cout <<"Less than relation"<<endl;
cout <<"***********"<<endl;
cout <<"Enter 2 number to calculate: "<<endl;
cin >> num1>>num2;
if (num1<num2)
{
total = num2;
return (total);
cout <<"The "<<num1<<" is smaller (<) than "<<num2<<endl;
}
else
cout << "The first number "<<num1<<"is not smaller than num2"<<endl;
total = num1;
return (total);
}
double greater_than_relation()
{
double num1,num2;
double total;
cout <<"Greater than relation"<<endl;
cout <<"***********"<<endl;
cout <<"Enter 2 number to calculate: "<<endl;
cin >> num1>>num2;
if (num1>num2)
{
total = num1;
cout <<"The "<<num1<<" is greater than (>) "<<num2<<endl;
return (total);
}
else
total = num2;
cout << "The first number "<<num1<<"is not greater than the second number "<<num2<<endl;
return (total);
} // end bracket of function
void quit2() // function of the second quit
{ // start bracket of the function
quit(); //called the 1st function of the quit..
} // end bracket of the function quit2
void calculator() // function of the calculator
{ //start bracket of the function
char opt; // variables of calculation function
cout <<"********Welcome To Calculator********"<<endl; //welcome screen of the void function......
cout <<"*************************************"<<endl; //****************************************
cout <<"Please chose an operator you want to used: "<<endl;
cout <<"+: Addition" <<endl;
cout <<"-: Subtraction" <<endl;
cout <<"*: multiplication"<<endl;
cout <<"/: division"<<endl; //All the operators options that user has available to used....
cout <<"^: sum squared"<<endl;
cout <<"<: less than relation"<<endl;
cout <<">: greater than relation"<<endl;
cout <<"c: clear sum"<< endl;
cout <<"q: quit"<< endl;
cin >>opt; //reads the opt input from the user
switch (opt) //switch statement for the previous option that user enter
{ // start bracket of the switch statement
case'+': // case 1 for addition
addition(); //called the function addition...
break; //break of the case addition
case'-': // case 2 for subtraction
subtraction(); // called the subtraction function....
break; // break of the case subtraction
case'*': // case 3 for multiplication
multiplication(); // called the multiplication function...
break; // break of the case multiplication
case'/': // case 4 for division
division(); // called the division function...
break; // break of the case division
case'^': // case 5 for sum squared...
sum_squared(); // called the sum_squared function
break; // break of the case sum squared
case'<': // case 6 for the less_than_relation function
less_than_relation(); // called the less_than_relation function
break; // break of the case less than relation
case'>': // case 7 for the greater_than_relation function
greater_than_relation(); // called the greater_than_relation function
break; // break of the case greater than relation
case'c': // case 8 for the clear function
// Nothing until know since the TOTAL SUM isn't works
break; // break of the case clear
case'q': // case 9 for the quit
quit2(); // called the quit2 function
break; // break of the case quit2
}//end bracket of the switch case
}// end bracket of the calculator function
int main(double total) // int main of the program include the total retrun
{ // start bracket of int main
char option1;
double val = 5.9; // all the variable of the int main
cout <<"********Welcome To Calculator********"<<endl;
cout <<"*************************************"<<endl;
cout <<"Please choose one of the following: ";
cout <<endl;
cout <<"1. Calculator "<<endl;
cout <<"2. Quit "<<endl;
cin >> option1;
while ((option1 == '1') || (option1=='2'))
{ // start bracket of while loop
if (option1 == '1') // if statement of the option1
{ // start bracket of if statement
calculator(); // called the calculator function if the option1 is 1
cout <<total<<endl; // print out the results of the two numbers
} // end bracket of if statement
else // else of if statement
if (option1 == '2') // if statement of option1 check if the user choose the second option
{ //start bracket of if statement
quit(); // called the function of quit...
break; // break of the while loop to stop the while
} // end of if statement
else // else of if statement
if ((option1!='1') || (option1!='2')) // if statement... check if the input of user is not 1 or 2
{ // start bracket of if statement
cout <<"Error Input... The program will exit in 5 seconds...."<<endl; // prints out an error message if the user add a wrong input
sleep ( val ); // sleep the program in 5 seconds
break; // break the program of while loop
}//bracket for if statement
}//bracket for while loop
return 0; // return to 0
} //bracket for int main