Hello All!
So task is two-old. I must ask the user for the number of students, which can be from 1-25. I must then ask for their first names, and sort the list alphabetically
I have created the cases first, that is, if the students are Zero, a single student and then more than one, but less than 25, and above 25.
I understand I could eliminate the single student case, but it's a unique situation, so I wanted to make a case for it.
After I figure out the cases, I will try to get an array setup to sort. But one thing at a time for me.
So right now, I don't even know how to properly initialize string of loneStudent. The following errors out. So here are a couple question to start.
1. How do I properly initialize the string of "loneStudent" for the single-student case?
2. How I do I go back to a specific line of code. I only want to write a single array sorting function, and have it referenced where appropriate.
3. Do you need anything else wrong? Am I going about this the wrong way?
Thank you!
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
// This program asks for a number of students in a class, then asks for their first names, then sorts the list alpahbetically
#include <iostream>
#include <string.h>
using std::cin;
using std::cout;
int main()
{
int countStudent = 0; // define variables
cout << "Please enter number of students.""\n"; // We first ask how many students.
cin >> countStudent;
if (countStudent == 0) {
cout << "You have no students!" << "\n";
cin.ignore();
return 0;
}
else if (countStudent == 1) {
cout << "What is the name of the student?" "\n";
cin << loneStudent
cout << "You only have a single student, nothing to sort, I will just repeat the name back!" << "\n";
cout << " <loneStudent>" "\n";
cin.ignore();
return 0;
}
else if (countStudent > 1 && countStudent < 25) {
cout << "What is the name of the student?" "\n";
cin << loneStudent
cout << "You only have a single student, nothing to sort, I will just repeat the name back!" << "\n";
cout << " <loneStudent>" "\n";
cin.ignore();
return 0;
}
else (countStudent >= 25){
cout << "Too many students, try again!" "\n";
cin.ignore();
return 0;
}
}
// Added Pause before ending program to allow output to display
cin.ignore();
return 0;
}
|