문제

I am trying to write a simple command line student database program and when the prompt begins the loop in the for loop it repeats 5 times when asking for the next student's name. What is wrong here? This is what I have.

Output:

Enter number of students in class: 5 Enter student name: John Smith Enter student name: Enter student name: Enter student name: Enter student name:


Code:

for (int i = 0; i < totalStudents; i++) {
    std::cout << "Enter student name: ";
    std::cin.get(studentName[i]);
    std::cin.ignore();
}
도움이 되었습니까?

해결책

This line: std::cout << "Enter student name: "; is inside the for loop so it displays 5 times. This is what you want to do. Just enter the name 5 times.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top