#include <iostream> //This includes the necessary Input/Output stream for basic commands for Cin/Cout.
usingnamespace std; //This is the namespace we are using (default std).
int main() //Our main class(an int)
{
int fun; // integer we are using to determine the user's choice of function.
double number1; // a user entered number1.
double number2; // a user entered number2.
cout << "List of Functions:\n"
<< "(1) Addition +\n(2) Subtraction -\n(3) Multiplication *\n(4) Division /\n\n"
<< "______________________________________________________\n\n"
<< "Please use the corrosponding number to select function\n"
<< "______________________________________________________\n\n";
cin >> fun; //Sets user input to the variable Sel.
if (fun == 1) // Determines if the user picks 1.
{
cout<<"\n";
cout << "Enter first number: ";
cin >> number1;
cout << "Enter second number: ";
cin >> number2;
cout << endl;
// adds the two numbers and displays the question and answer for the user
cout << number1 << " + " << number2 << " = " << number1 + number2 << endl << endl;
}
if (fun == 2) // Determines if the user picks 2.
{
cout<<"\n";
cout << "Enter first number: ";
cin >> number1;
cout << "Enter second number: ";
cin >> number2;
cout << endl;
// subtracts the two numbers and displays the question and answer for the user
cout << number1 << " - " << number2 << " = " << number1 - number2 << endl << endl;
}
if (fun == 3) // Determines if the user picks 3.
{
cout<<"\n";
cout << "Enter first number: ";
cin >> number1;
cout << "Enter second number: ";
cin >> number2;
cout << endl;
// multiplies the two numbers and displays the question and answer for the user
cout << number1 << " * " << number2 << " = " << number1 * number2 << endl << endl;
}
if (fun == 4) // Determines if the user picks 4.
{
cout<<"\n";
cout << "Enter first number: ";
cin >> number1;
cout << "Enter second number: ";
cin >> number2;
cout << endl;
// divides the two numbers and displays the question and answer for the user
cout << number1 << " / " << number2 << " = " << number1 / number2 << endl << endl;
}
system ("PAUSE>nul");
return 0;
}
#include <iostream> //This includes the necessary Input/Output stream for basic commands for Cin/Cout.
#include <math.h> //for pow(x,y) function
usingnamespace std; //This is the namespace we are using (default std).
int main() //Our main class(an int)
{
int fun; // integer we are using to determine the user's choice of function.
double number1; // a user entered number1.
double number2; // a user entered number2.
bool done = false;
char choice;
while(!done)
{
cout << "List of Functions:\n"
<< "(1) Addition +\n(2) Subtraction -\n(3) Multiplication *\n(4) Division /\n\n"
<< "______________________________________________________\n\n"
<< "Please use the corrosponding number to select function\n"
<< "______________________________________________________\n\n";
cin >> fun; //Sets user input to the variable Sel.
if (fun == 1) // Determines if the user picks 1.
{
cout<<"\n";
cout << "Enter first number: ";
cin >> number1;
cout << "Enter second number: ";
cin >> number2;
cout << endl;
// adds the two numbers and displays the question and answer for the user
cout << number1 << " + " << number2 << " = " << number1 + number2 << endl << endl;
}
if (fun == 2) // Determines if the user picks 2.
{
cout<<"\n";
cout << "Enter first number: ";
cin >> number1;
cout << "Enter second number: ";
cin >> number2;
cout << endl;
// subtracts the two numbers and displays the question and answer for the user
cout << number1 << " - " << number2 << " = " << number1 - number2 << endl << endl;
}
if (fun == 3) // Determines if the user picks 3.
{
cout<<"\n";
cout << "Enter first number: ";
cin >> number1;
cout << "Enter second number: ";
cin >> number2;
cout << endl;
// multiplies the two numbers and displays the question and answer for the user
cout << number1 << " * " << number2 << " = " << number1 * number2 << endl << endl;
}
if (fun == 4) // Determines if the user picks 4.
{
cout<<"\n";
cout << "Enter first number: ";
cin >> number1;
cout << "Enter second number: ";
cin >> number2;
cout << endl;
// divides the two numbers and displays the question and answer for the user
cout << number1 << " / " << number2 << " = " << number1 / number2 << endl << endl;
}
cout << "Would you like to do another calculation Y/N ";
cin >> choice;
if (choice == 'N' || choice == 'n')
{
done = true;
}
}
//system ("PAUSE>nul");
return 0;
}
thanks a lot!
just one more question sorry. Sent program to my friend and burned it onto disc and tried on different computer and i got an error when trying to open the .exe
THe application has failed to start because its side-by-side configuration is incorect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
I was wondering how I make it so that instead of the user pressing 5 to carry out the sqaure function they can press 's'.
All my 'fun' inputs are set as integers, so my program is looking for an integer rather than a letter all the time. At the moment if i enter a letter the program repeats and repeats really quickly so the program flickers.
I've tried looking at the ASCII code table and tried 115 which equals s but it hasnt worked... :s
tempChar = cin.peek();
cin >> fun; //Sets user input to the variable Sel.
if (tempChar == 's')
{
cin.clear();
cin.ignore(1);
fun = 5; //or do code here
}
and add the tempChar like this
1 2 3
bool done = false;
char choice;
char tempChar; //add this line