I need help with this particular programming assignment. Here goes.
Ask the user how many students are in a class. Using a loop, the application should read in all of the student names. When all the names have been read in the application should report how many students fall into each range A-F, G-K, L-Q, R-V, W-Z. The output should be properly formatted into rows and columns. For example if there are four students, Abraham, Deidra, Billy, and Wyatt. The first column, A-F would have 3 students, column G-K would have 0, column L-Q would have 0, column R-V would have 0, and column W-Z would have 1 student. You can assume the first names will all start with a capital letter and no students will have the same name.
Input Validation: The number of students can not be below 1 or greater than 25.
Here is the code I have written so far. I've made it to the input validation but I don't understand how I group the user input into columns for output.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int studentAmount;
string studentName, firstStudent, lastStudent;
cout << "How many students are in the class?" << endl;
cin >> studentAmount;
while(studentAmount < 1 || studentAmount > 25)
{
cout << "Error. The number of students cannot be below 1 or greater than 25" << endl << "Enter a valid amount."
<< endl;
cin >> studentAmount;
}
When all the names have been read in the application should report how many students fall into each range A-F, G-K, L-Q, R-V, W-Z.
From that statement it appears you only need to count the number of students in each group. It does not say that you have to print a table of the student names.
Perhaps the easiest is to create 5 groups.
1 2 3 4 5 6
int groupAF = 0;
int groupGK = 0;
int groupLQ = 0;
int groupRV = 0;
int groupWZ = 0;
When you read in a name, determine from the first letter which group to increment.
The first column, A-F would have 3 students,
Now, that seems to imply you are to print the names in a column. That's a different problem.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Thanks...after further dissection I've determined I'm not printing the names in the columns, just the number count. Any advice on how to do this..."When you read in a name, determine from the first letter which group to increment."
Just use a series of if statements to determine the group.
1 2 3 4 5 6 7
char c = studentName[0]; // Get first character of name
if (c >= 'A' && c <= 'F')
groupAF++;
elseif (c >= 'G' && c <= 'K')
groupGK++;
elseif ...
// keep going for the remaining groups