#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)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.