Functions

Write your question here.
I'm really lost with this code I dont really have a clue Im not trying to cheat I just work better off a finished code.

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
#include <iostream>
	using namespace std;

	double percent(int, int);

	int main()
	{
		int ptsEarned,			// number of points earned on a test
			ptsPossible;		// number of points possible on a test

		double testPercent;		// percent of points possible earned on a test

		cout << "This program will test the percent function you wrote." << endl;
		cout << "Let's use it to calculate the percent earned on a test." << endl;
		cout << "Please enter the number of points possible on a test: " << endl;
		cin >> ptsPossible;

		cout << "Now enter the number of points earned on the test: ";
		cin >> ptsEarned;

		// Write the line of code to call function percent


		cout << "The percent for that test result is " << testPercent << endl;

		return 0;
What there is to "work off" in finished code?
Try "read": http://www.cplusplus.com/doc/tutorial/functions/
You have a function prototype however you are completely missing a function declaration. Also for the prototype you should have double percent(int ptsEarned, int ptsPossible);

Also what are you lost with?
Last edited on
Also for the prototype you should have double percent(int ptsEarned, int ptsPossible);


For a function declaration/definition there is no requirement to name a parameter if it's not used. So for the prototype (declaration), double percent (int, int); is fine - although for the definition then names would be needed.

Topic archived. No new replies allowed.