I am attempting to create a menu function that allows the user to enter in which option he wants (+, -, *, or /) and then take him to the correct function, such as a function to add or multiply numbers.
Do I still call all of the functions in the class or do I just call the menu function and after the user inputs their choice, have that input take them to the correct function?
Here is what I have so far:
I'm just wondering if the way I have it now (which isn't yet working) which uses if...else statements or whether a switch would work better.
#include <fstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
using namespace std;
class Program
{
//declaring variables
private:
int a;
int b;
int c;
int d;
string operation;
//calling functions
public:
void menu(string operation);
void addFractions(int a, int b, int c,int d);
void subtractFractions(int a, int b, int c,int d);
void multiplyFractions(int a, int b, int c,int d);
void divideFractions(int a, int b, int c,int d);
};
//function menu
void Program::menu(string operation)
{
cout << "Welcome to the Fraction Calculator.";
cout << "This program allows you to enter in two fractions";
cout << "and will perform whatever operation you choose.";
cout << "Please enter in integer values for the variables a, b, c, and d.";
cout << "The values of b and d cannot equal zero.";
cout << "Please choose the operation you would like to perform:";
cout << "+ (addition), - (subtraction), * (multiplication), or / (division)";
cin >> operation; //get the request
cout << endl;
if (operation = +)
{
goto void addFractions(int a, int b, int c,int d);
}
else if (operation = -)
{
goto void subtractFractions(int a, int b, int c,int d);
}
else if (operation = *)
{
goto void multiplyFractions(int a, int b, int c,int d);
}
else if (operation = /)
{
goto void divideFractions(int a, int b, int c,int d);
}
else
{
cout << "Your input was invalid, please try again";
}
}
void Program::addFractions(int a, int b, int c,int d)
{
Start Free Trial