Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> #include <cstring> using namespace std; int main() { int stu

ID: 3631159 • Letter: #

Question

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
int students;
char first[20] = "Amy";
char last[20] = "Yolanda";
char name[20];

cout <<" Enter the number of students in the class: ";
cout <<"(Enter a value in the range 1-25): ";
cin >> students;

for (int i = 1; i < students+1; i++)
{
cout <<" Enter name of student " << i << " : ";
cin >> name[20];

if (strcmp(name, first) < 0)
{
strcmp(first, name);
}
if (strcmp(name, last) > 0)
{
strcmp(last, name);
}

}
cout << "The first student is " << first << endl;
cout << "The last student is " << last << endl;

system("pause");
return 0;
}



can anyone help me with this c++ program, keeps telling me i have errors. don't understand why it won't debug.

Explanation / Answer

change cin >> name[20]; to cin >> name;
then put cin.ignore(); after each line of cin >>

such as

cout <<"(Enter a value in the range 1-25): ";
cin >> students;
cin.ignore();

for (int i = 1; i < students+1; i++)
{
cout <<" Enter name of student " << i << " : ";
cin >> name;
cin.ignore();

if (strcmp(name, first) < 0)