return 0; ...

This program succeeds, and its runs but, it doesnt to anything. Everytime i run it the "press any key to continue...". Any reasons why this doesnt work?

#include <iostream>
#include <cmath>

using namespace std;

void addition();
void subtraction();
void multiplication();
void division();
void exponentation();
void logarithm();
void factorial();
int factorial(int num);

char character;


int main()
{
cout << "Enter:" << endl;
cout << "+ for the addition operation" << endl;
cout << "- for the subtraction operation" << endl;
cout << "* for the multiplication operation" << endl;
cout << "/ for the division operation" << endl;
cout << "^ for the exponentiation operation" << endl;
cout << "l for the base-10 logarithm operation" << endl;
cout << "! for the factorial operation and" << endl;
cout << "q to quit." << endl;

switch (character)
{
case '+' : addition();
break;
case '-' : subtraction();
break;
case '*' : multiplication();
break;
case '/' : division();
break;
case '^' : exponentation();
break;
case 'l' : logarithm();
break;
case '!' : factorial();
break;
case 'q' : return 0;
}

}

void addition()
{
int number1;
int number2;
int sum;

cout << "Please input two integer numbers:" << endl;
cin >> number1;
cin >> number2;

sum = number1 + number2;

cout << "The sum of the two numbers is " << sum << "." << endl;
}

void subtraction()
{
int number1;
int number2;
int difference;

cout << "Please input two integer numbers:" << endl;
cin >> number1;
cin >> number2;

difference = number1 - number2;

cout << "The difference of the two numbers is " << difference << "." << endl;
}

void multiplication()
{
int number1;
int number2;
int product;

cout << "Please input two integer numbers:" << endl;
cin >> number1;
cin >> number2;

product = number1 * number2;

cout << "The product of the two numbers is " << product << "." << endl;
}

void division()
{
int number1;
int number2;
int quotient;

cout << "Please input two integer numbers:" << endl;
cin >> number1;
cin >> number2;

quotient = number1 / number2;

cout << "The quotient of the two numbers is " << quotient << "." << endl;
}

void exponentation()
{
int number1;
int number2;
int exponent;

cout << "Please input two integer numbers:" << endl;
cin >> number1;
cin >> number2;

exponent = number1 ^ number2;

cout << "The exponent of " << number1 << "^" << number2 << " is " << exponent << "." << endl;
}

void logarithm()
{
float number;
float logarithm;

cout << "Please input a float number:" << endl;
cin >> number;

logarithm = log10(number);

cout << "The logarithm of log10(" << number << ") is " << logarithm << "." << endl;
}

void factorial()
{
int num1, factor;
cout << "Please enter a number to do the Factorial." << endl;
cin >> num1;
factor = factorial(num1);
cout << num1 << " ! =" << factor << endl;
}

int factorial(int num)
{
int i;
int result = 1;
for ( i = 1; i <= num; ++i)
{
result = result *=i;
}

return result;
}
You never input character, therefore it does not match any of the switch cases. Also, the return 0; should
really be outside of the switch statement, but that's another story.
Last edited on
haha wow im retarded...and would it still work with the return 0; inside or no?
nvm, ha thanks, sorry im a doorknob lol.
Topic archived. No new replies allowed.