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)
// Example program
#include <iostream>
#include <string>
usingnamespace 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.
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.