Array doesnt print properly/ not assigned?

Hi, I am trying to get 5 quiz scores, 3 exam scores, and 1 final exam score in this bit of code. However, when I run this and print it out, the last quiz value is 0 and then the first exam value is the last quiz value. I have no clue what is wrong with my code. Any help would be greatly appreciated :)

void get_scores()
{
cout << "Please enter your final exam score." << endl;

{
cin >> fexam;
}
cout << " Please enter your quiz scores."<<endl;
for (int i = 0; i < 4; ++i)


{
cin >> quiz[i];
}

cout << "Please enter your exam scores." << endl;
for (int i = 0; i < 2; ++i)
{
cin >> exams[i];
}

}
This is how they are declared:
int exams [3] ; //amount of exams
int quiz [5] ; //amount of quizzes
int fexam; //amount of finals exams
Last edited on
You have 5 quiz scores but input only 4: for (int i = 0; i < 4; ++i) { cin >> quiz[i]; }
You have 3 exam scores but input only 2: for (int i = 0; i < 2; ++i) { cin >> cin >> exams[i]; }

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>

using namespace std;

const int NUM_EXAMS = 3;
const int NUM_QUIZZES = 5;

int main () 
{
  int exams[NUM_EXAMS]; //amount of exams
  int quiz[NUM_QUIZZES]; //amount of quizzes
  int fexam; //amount of finals exams 

  cout << "Your quiz scores\n";
  for (int i = 0; i < NUM_QUIZZES; i++)
  {
    cout << "Please enter the quiz score[" << i << "]: ";
    cin >> quiz[i];
  }

  cout << "Your exam scores\n";
  for (int i = 0; i < NUM_EXAMS; i++)
  {
    cout << "Please enter the exam score[" << i << "] :";
    cin >> exams[i];
  }
   
  cout << "\nThe values you entered: ";
  cout << "\n\nExams: ";
  for (int i = 0; i < NUM_EXAMS; i++)
  {
    cout << exams[i] << '\t';
  }
  cout << "\n\nQuizzes: ";
  for (int i = 0; i < NUM_QUIZZES; i++)
  {
    cout << quiz[i] << '\t';
  }
  system ("pause");
  return 0;
}
Topic archived. No new replies allowed.