Help with functions assignment

Hi I am new to C++ and I am stuck on this assignment so I need help

Write a program which uses functions to compute some information about a car trip:

Function intro will print your name, your course (CP1) and (Duke), Exercise 3, and a brief (one line) description of the program.
Function mpg will have two parameters: the number of miles driven (an int) and the gallons of gas used (a float). The function will compute and return the miles driven per gallon of gas used (a float). This function doesn't print anything.
Function tripcost will have three parameters: the cost of a gallon of gas (a float), the gallons of gas used (a float), and the cost of tolls (a float). The function will compute and return the total cost of the trip (a float). This function doesn't print anything.
Function main will:
1)Call function intro.
2)Prompt the user for the number of miles driven and the gallons of gas used.
3)Call function mpg and pass these values to it. After the call, print a message giving the miles per gallon used on the trip.
4)Prompt the user for the cost of a gallon of gas, and the cost of tolls for the trip.
5)Call function tripcost and pass the cost of a gallon, the cost of tolls, and the gallons of gas used to the function. After the call, print a message giving the total cost of the trip.
Last edited on
What are you having trouble with? Note that we aren't a do-your-homework-for-you site, but we can help with specific questions.

Break the assignment down into bite-sized parts.
The first task talks about a function called "intro".
Do you know how to define a function? If not, go to: http://www.cplusplus.com/doc/tutorial/functions/

"print your name" -- Do you know how to print things?
If not, go to: http://www.cplusplus.com/doc/tutorial/basic_io/ and read about Standard Output
Yeah I know how to do those. I am confused on what does it mean by call function mpg?
If the name of the function is mpg, and it takes in an int and a float, you need to call it correspondingly.

1
2
3
4
5
6
7
8
9
float mpg(int miles_driven, float gallons_used)
{
    return 42.0f;   // TODO
}

int main()
{
    float miles_per_gallon = mpg(10, 12.3f);
}
Last edited on
Topic archived. No new replies allowed.