Help returning values

Schwing bong too late!
Last edited on
Line 6 you say void getData(int speedLimit, int driverSpeed); which means you declared a function called getData that returns no value. It also takes in two int values called speedLimits and driverSpeed however these are the values you want to return. I would also suggest creating two different functions to get each value unless you have a good understanding of structs and passing them into functions. If not then... (forgive me for any errors I'm not using a compiler)

declare a function to get speedLimit. This will return an int, which is of course the speedLimit.
int getSpeedLimit(); //Notice it doesn't accept any values because the function does not need to use any.

Declare another function to get driverSpeed. Same as before.
int getDriverSpeed();

Function for getSpeedLimit will look like this:
1
2
3
4
5
6
7
int getSpeedLimit()
{
     int speedLimit = 0;
     cout << "What was the speed limit?" << endl;
     cin >> speedLimit;
     return speedLimit;
}


function for getDriverSpeed will look like
1
2
3
4
5
6
7
int getDriverSpeed()
{
     int driverSpeed = 0;
     cout << "What was the driver's speed? " << endl;
     cin >> driverSpeed;
     return driverSpeed;
}


Call in main() [<---get rid of the void in yours. you don't need it.] should look like:
1
2
3
4
5
6
7
int main()
{
     int speedLimit;
     int driverSpeed;
     speedLimit = getSpeedLimit();
     driverSpeed = getDriverSpeed();
} 


Once that is done calcFine will be called in main like this:
calcFine(speedLimit, driverSpeed);


F****' Savage m8 Lol
Last edited on
Topic archived. No new replies allowed.