when i ask user to input name number 1 it pauses like it is supposed to and allows the user to input their name. when it asks the user to input name #2 it skips right into the loop and displays "enter test score 1" before the user has a chance to enter their name. why isnt cin.getline pausing the program like its supposed to and like it did with name 1?
Code:
#include <iostream>
using namespace std;
int main()
{
char names[5][50];
char grades[5];
double set1[4];
double set2[4];
double set3[4];
double set4[4];
double set5[4];
double total1 = 0;
double total2 = 0;
double total3 = 0;
double total4 = 0;
double total5 = 0;
cout << "Enter student #1 name: ";
cin.getline(names[0], 50);
for (int j = 0; j < 4; j++)
{
cout << "Enter test score #" << j+1 << ": ";
cin >> set1[j];
total1 += set1[j];
}
cout << "Enter student #2 name: ";
cin.getline(names[1], 50);
for (int j = 0; j < 4; j++)
{
cout << "Enter test score #" << j+1 << ": ";
cin >> set2[j];
total2 += set2[j];
}
cout << "Enter student #3 name: ";
cin.getline(names[2], 50);
for (int j = 0; j < 4; j++)
{
cout << "Enter test score #" << j+1 << ": ";
cin >> set3[j];
total3 += set3[j];
}
cout << "Enter student #4 name: ";
cin.getline(names[3], 50);
for (int j = 0; j < 4; j++)
{
cout << "Enter test score #" << j+1 << ": ";
cin >> set4[j];
total4 += set4[j];
}
cout << "Enter student #5 name: ";
cin.getline(names[4], 50);
for (int j = 0; j < 4; j++)
{
cout << "Enter test score #" << j+1 << ": ";
cin >> set5[j];
total5 += set5[j];
}
return 0;
}