Help with arrays and functions

Hi, I'm new to this and am supposed to write a program that will grade a test with a percent grade with fifteen questions with the answers:

1. A
2. B
3. C
4. D
5. A
6. B
7. C
8. D
9. A
10. B
11. C
12. D
13. A
14. B
15. C

It is supposed to have two functions (one called numbercorrect and one called inputanswer) and the program is meant to have the user input answers for the fifteen questions then have them compared with the correct answers, then finally given a percentage grade at the end. I'm really stuck so far, can anyone give me a hand with the functions and really in general? Here is what I have so far:

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

void inputAnswer(char given[]);
void numbercorrect(char numberRight, int questions);

int main()
{
	char cAnswers[] = { 'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'C' };
	char questions[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

	char inputAnswer(int questions);
	{
		int count;
		cout << "Please enter your answer for question #" << (count + 1) << ": ";
		cin >> questions;
	}
	{
		cout << "Your quiz grade is: " << +10 * numberRight + "%";
	}

	int numberCorrect(char numberRight, int questions);

	return 0;
	}
closed account (48T7M4Gy)
Perhaps if you tell us where you got stuck. If you got that far all on your own I think you could be a bit more specific where you got 'stuck'.

Hint: you need a loop of some sort.
Oh ok, I know that I need a loop that will basically be something along the lines of i<10 in order to make the loop to stop. I also know that I need two functions, one for inputting the answers and one to compare te answers with the correct answers. I'm confused on how to write the functions themselves, I'm working on the loop right now. Also I'm not sure where in the code I should call upon the functions as I know that they will end up at the bottom of the code.
I'm not looking for someone to do this for me but some sort of similar example would be great so that I can see what goes where and how the functions are made.
closed account (48T7M4Gy)
If you have 15 questions then your loop would count to 15 not 10?

Remember that an array starts at an index of 0 so any loop would be for i=0; i < 15; i++
Just treat the function as a small program which you send values to and get a reply value, message or whetver back.

In main if you want to call the method then you would write:

1
2
3
4
5
6
7
8
9
10
int main()
{
  ... some code
  int xyz;
  quest = 1;
  char num = '?'
  ... more code 
    xyz = numberCorrect(num, quest);
  ... whatever stuff you need here too
}


Last edited on
Topic archived. No new replies allowed.