Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Please help me /prog/

Name: Anonymous 2007-11-11 22:10

I have this due for my class tomorrow and I can't figure out why this wont work. When it prompts the user to input something for the "selection" variable it completely ignores what is put into it and just goes right to the addition function. I know it's a problem with the if area, but I can't find anything wrong with my limited knowledge. Please help.

#include <cstdlib>
#include <iostream>

using namespace std;

int multiplication(int a, int b);
int division(int a, int b);
int addition(int a, int b);
int subtraction(int a, int b);


int main()
{
    int answer;
    int selection;
    int a;
    int b;
    cout << "Please enter a positive number: ";
    cin >> a;
    cout << "\n\nPlease enter another positive number: ";
    cin >> b;
    cout << "\n\nDo you want to add, subtract, multiply, or divide?";
    cout << "\n\nPress enter 1 for addation, 2 for subtraciton, 3 for";
    cout << "\nmultiplication, or 4 for division." << endl;
    cin >> selection;
    if (selection = 1)
    {
                 answer = addition(a,b);
                 cout << "\n\nThe answer is: " << answer << endl;
                 char response;
                 cin >> response;
                 return 0;
   
    if (selection = 2)
                 answer = subtraction(a,b);
                 cout << "\n\nThe answer is: " << answer << endl;
                 char response2;
                 cin >> response2;
                 return 0;
                
    if (selection = 3)
                 answer = multiplication(a,b);
                 cout << "\n\nThe answer is: " << answer << endl;
                 char response3;
                 cin >> response3;
                 return 0;
    
    if (selection = 4)
                 answer = division(a,b);
                 cout << "\n\nThe answer is: " << answer << endl;
                 char response4;
                 cin >> response4;
                 return 0;
                 }
    }
   
  


int addition(int a, int b)
{
      int c;
      return c = a + b;
      }
     
int subtraction(int a, int b)
{
      int c;
      return c = a - b;
      }

int multiplication(int a, int b)
{
      int c;
      return c = a * b;
      }
     
int division(int a, int b)
{
      int c;
      return c = a / b;
      }

Name: Anonymous 2007-11-11 23:25

>>1
your code makes me cry.  why do you want me to cry?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List