Helping input different variables/void lines of code

So my professor wanted me to create a force calculator, so I made the basic force calculator. Now he said he wants me to include different criteria to get the max grade, and I can't figure out where/what to do to include them. Please let me know if you understand what he wants and where he wants me to put them. Thank you so much!
void handleMenuControl()
void displayMenu()
double force(double mass)
void force(double mass, double acceleration, double& result)

Thank you!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  // Example program
#include <iostream>
#include <string>

using namespace std;

int main()

{
    int choice;
    cout << " 1. Peform force calculation with acceleration as 9.8m/s^2 " << endl;  //Choice 1 Output
    cout << " 2. Perform force calculation, specifying acceleration " << endl;   //Choice 2 Output
    cout << " 3. Exit " << endl;                                        //Exit Output
    cin >>  choice;                                     //Allows input to be choice
    system ("pause");                                       //Pauses System


if (choice == 1)                    //If the choice is 1, runs this.
    {    
         float mass;
         float force;
         float acc = 9.8;
         cout << "Input mass: ";            //Prompts user to input mass
         cin >> mass;               //Allows for mass input
         force = mass * acc ;           //Multiplies mass and acceleration
         cout << "The force is: " << force << endl;     //Outputs force
    
    system ("Pause") ;
    }
if (choice == 2)                //If the choice is 2, runs this.
    {
            float mass;
            float force;
            float acc;
            cout << "Input mass (assumed in kg): ";     //Prompts user to input mass
            cin >> mass;                            //Allows for mass input
            cout << "Input Acceleration (assumed in m/s^2): ";      //Prompts user to input acceleration
            cin >> acc;                         //Allows for acceleration input
            force = (mass * acc);               //Calculates force by multiplying mass and acceleration
            cout << "The force is: " << force << endl;      //Outputs Force
            system ("pause");
    }

if (choice == 3)                //If the choice is 3, runs this.
    {
        exit(0);            //Exits program
    }
    
if (choice < 0 || choice > 3)   //Any other input, Run error message
    {
        cout << " Error: incorrect input " << endl;
        system ("pause");
    }
return 0;                       //Exits Program
}
You have now only one function -- main() -- and all the code within it. Well, not exactly; you do call functions system(), exit(), cin::op>> and cout::op<< too.

The text outside your code
1
2
3
4
void handleMenuControl()
void displayMenu()
double force(double mass)
void force(double mass, double acceleration, double& result)

look like more functions.

For example, the second force() seems to have mass and acceleration as input parameters, computes something with them, and stores result in parameter 'result'. It is quite likely that your code that now has force = mass * acc; should have force( mass, acc, force ); instead and the multiplying code would be in the body of the function.

You have had functions, function parameters, by reference parameters, etc already?
If not, see: http://www.cplusplus.com/doc/tutorial/functions/
Topic archived. No new replies allowed.