Advertisement

12.03.2006 at 06:54PM PST, ID: 22081000
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

C++ menu question - VERY URGENT

Asked by alligarbage in Miscellaneous Programming

Tags: ,

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
 
Loading Advertisement...
 
[+][-]12.04.2006 at 12:36AM PST, ID: 18066984

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Miscellaneous Programming
Tags: menu, function
Sign Up Now!
Solution Provided By: wwfarch
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-44