This program is supposed to ask the user for 2 numbers first, then print out a menu asking which operation they would like to perform on the number, then output the result. the problem is, there needs to be a function for getting the numbers, functions for each operator, and another function to display the output. I am stuck in sending the numbers to the operators to perform the operation

#include <iostream>
using namespace std;

void menu(),choice(int ans); 
double num();
double add();
void sub(),multi(),divi(),exit();
double res;
double num1;
double num2;

int main()
{
     num();
     menu();
     
     return 0;
}

void menu()
{
     int ans;
     do
     {
          cout << "What would you like to do?\n";
          cout << "1: Addition\n";
          cout << "2: Subtraction\n";
          cout << "3: Multiplication\n";
          cout << "4: Division\n";
          cout << "5: Exit\n";
               cin  >> ans;
          choice(ans);
     }while(ans!=5);
}

void choice(int ans)
{
     switch (ans)
     {
          case 1:
               result = add();
               cout << "The answer is "<< result << "." << endl;
               cout << "\n";
               break;
          case 2:
               sub();
               break;
          case 3:
               multi();
               break;
          case 4:
               divi();
               break;
          case 5:
               exit();
               break;
          default:
               cout << "Please read and follow all directions\n";/
               break;
     }
}


double num()
{
     double add;
     double num1;
     double num2;
     cout << "First number? ";
     cin >> num1;
     cout << "Second number? ";
     cin >> num2;
     
     add = num1 + num2;
     
     return add;
}

double add()
{
     
     return result;
}

void sub()
{
}

void multi()
{
}

void divi()
{
}

void exit()
{
}

Look's like your confused about passing arguments. Actually, it look's like you don't understand, or you didn't write half the code up there. Here's what you need to do:

1. Write a function that will take two int pointer's as arguments. Get the user input and write the values into the pointer adresses.

2. Write a function that will take two integers as arguments. The function will print a menu and ask for the user input (of what operation is wanted). Return the result (int) of the coresponding math function, passing the two integers.

3. Write the math function's. They take two integer argument's, and return the result (int).

4. Write the main function. It will make two integer's. Call the input function passing the address of both integers. Next, print the result of the menu function, passing both integers.

Oh yeah, forgot the print function. Oww well, I guess I'll leave that up to you. Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.