My only guess is I should be using getline(cin, var) instead of just cin but i played with //it and had no success .
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <conio.h>
#include <cstring>
using namespace std;
const int CLASS = 4,
COLS = 4, ROWS = 4, NEW_GRADE = 24;
void goSplash();
void showMenu( const int , const int, const int ,const int ,const int ,const int ,int &);
void goSort(int[] , const int);
int main()
{
const int CLASS1 = 1, CLASS2 = 2,
CLASS3 = 3,
CLASS4 = 4,
CLASS5 = 5,
CLASS_ALL = 6;
int choice;
int newGrade[CLASS];
string classArray[CLASS];
int tableGrade[ROWS][COLS];
cout <<"\nThis program will allow you to view and manipulate your,\n";
cout<<"test scores in in four quarter semester.\n";
cout<<"Your will list four subjects and or classes and than your scores.\n";
cout<<"Your can view your scores, average them or sort them by class."<<endl;
cout<<"\nPLEASE PRESS ENTER TO START PROGRAM"<<endl;
_getch();
system("CLS");
goSplash();
for (int count = 0; count < CLASS; count++)
{
cout <<"\nEnter the name of class ("<<count + 1<<") : ";
cin>>classArray[count];
}
for (int val = 0, num = 0; val < COLS; val ++)
{
do
{
cout <<"\nEnter score number "<<num +1<<" in percent out of 100 for "<< classArray[val]<<" : ";
cin >> tableGrade[num][val];
while (tableGrade[num][val] < 0 || tableGrade[num][val] > 100)
{
cout<<"The value must be between 0 and 100: ";
cin >> tableGrade[num][val];
cout<<"\n";
}
if (cin.fail())
{
cin.clear();
cin.ignore(INT_MAX, '\n');
}
}while (cin.fail());
}
for (int val = 0, num = 1; val < COLS; val ++)
{
do
{
cout <<"\nEnter score number "<<num +1<<" in percent out of 100 for "<< classArray[val]<<" : ";
cin >> tableGrade[num][val];
while (tableGrade[num][val] < 0 || tableGrade[num][val] > 100)
{
cout<<"The value must be between 0 and 100: ";
cin >> tableGrade[num][val];
cout<<"\n";
}
if (cin.fail())
{
cin.clear();
cin.ignore(INT_MAX, '\n');
}
}while (cin.fail());
}
for (int val = 0, num = 2; val < COLS; val ++)
{
do
{
cout <<"\nEnter score number "<<num +1<<" in percent out of 100 for "<< classArray[val]<<" : ";
cin >> tableGrade[num][val];
while (tableGrade[num][val] < 0 || tableGrade[num][val] > 100)
{
cout<<"The value must be between 0 and 100: ";
cin >> tableGrade[num][val];
cout<<"\n";
}
if (cin.fail())
{
cin.clear();
cin.ignore(INT_MAX, '\n');
}
}while (cin.fail());
}
for (int val = 0, num = 3; val < COLS; val ++)
{
do
{
cout <<"\nEnter score number "<<num +1<<" in percent out of 100 for "<< classArray[val]<<" : ";
cin >> tableGrade[num][val];
while (tableGrade[num][val] < 0 || tableGrade[num][val] > 100)
{
cout<<"The value must be between 0 and 100: ";
cin >> tableGrade[num][val];
cout<<"\n";
}
if (cin.fail())
{
cin.clear();
cin.ignore(INT_MAX, '\n');
}
}while (cin.fail());
}
for (int val = 0, num = ROWS; val < COLS; val ++)
{
do
{
cout <<"\nEnter score number "<<num +1<<" in percent out of 100 for "<< classArray[val]<<" : ";
cin >> tableGrade[num][val];
while (tableGrade[num][val] < 0 || tableGrade[num][val] > 100)
{
cout<<"The value must be between 0 and 100: ";
cin >> tableGrade[num][val];
cout<<"\n";
}
if (cin.fail())
{
cin.clear();
cin.ignore(INT_MAX, '\n');
}
}while (cin.fail());
}
showMenu(CLASS1, CLASS2, CLASS3, CLASS4, CLASS5, CLASS_ALL, choice);
while (choice < 1 || choice > 7)
{
cout<"Please choose an option from 1 to 6: ";
cin>>choice;
if (choice==7)
{
system("PAUSE");
exit;
}
}
switch (choice)
{
case 1:
cout <<"Your Grades for "<< classArray[0] << " are.\n";
for (int num =0; num < COLS; num++ )
{
cout<<"Grade: "<<num +1<< tableGrade[num][0]<<"\n";
}
break;
case 2:
cout <<"Your Grades for "<< classArray[1] << " are.\n";
for (int num =0; num < COLS; num++ )
{
cout<<"Grade: %"<<num +1<< tableGrade[num][1]<<"\n";
}
break;
case 3:
cout <<"Your Grades for "<< classArray[2] << " are.\n";
for (int num =0; num < COLS; num++ )
{
cout<<"Grade: %"<<num +1<< tableGrade[num][2]<<"\n";
}
break;
case 4:
cout <<"Your Grades for "<< classArray[3] << " are.\n";
for (int num =0; num < COLS; num++ )
{
cout<<"Grade: "<<num +1<< tableGrade[num][3]<<"\n";
}
case 5:
cout <<"Your Grades for "<< classArray[4] << " are.\n";
for (int num =0; num < COLS; num++ )
{
cout<<"Grade: "<<num +1<< tableGrade[num][4]<<"\n";
}
case 6:
cout<<"The sorted grades for your classes are.\n";
for(int var = 0, big =0; var < COLS; var ++, big++){newGrade[big] = tableGrade[0][var]; }
for(int var = 0, big =5; var < COLS; var ++, big++){newGrade[big] = tableGrade[1][var]; }
for(int var = 0, big =10; var < COLS; var ++, big++){newGrade[big] = tableGrade[2][var]; }
for(int var = 0, big = 15; var < COLS; var ++, big++){newGrade[big] = tableGrade[3][var]; }
for(int var = 0, big = 20; var < COLS; var ++, big++){newGrade[big] = tableGrade[4][var]; }
goSort(newGrade, NEW_GRADE);
break;
default:
cout<<"Error invalid input entered"<<endl;
break;
}
cout<<"Do you wish to exit the program now\n";
cout<<
system("PAUSE");
exit;
}
void goSplash()
{
int count = 1000;
while (count > 0)
{
count--;
cout<<"101101111100000001101010010100100100111110010101001010101110101";
if (count%5==0)
{
cout<<"%^%&^(^&(^*%^%*%%^$(^&%^$*$*$%*$%*%**%*";
}
}
cout<<setw(50)<<"CHRIS'S GRADE KEEPER";
system("CLS");
}
void showMenu(const int CLASS1, const int CLASS2, const int CLASS3, const int CLASS4, const int CLASS5, const int CLASS_ALL, int &choice)
{
const int EXIT = 7;
cout<<"*****MENU*****\n";
string menuStar = "*****";
for (int menu=50; menu > 5; menu -=5 )
{
cout<<menuStar<<endl;
}
cout<<"\n";
cout<<CLASS1<<"-- to display you first class scores\n";
cout<<CLASS2<<"-- to display you second class scores\n";
cout<<CLASS3<<"-- to display you third class scores\n";
cout<<CLASS4<<"-- to display you fourth class scores\n";
cout<<CLASS5<<"-- to display you fifth class scores\n";
cout<<CLASS_ALL<<"--to display all of your class scores sorted\n";
cout<<EXIT<<"--to exit the program\n\n";
cout<"Please choose an option from 1 to 7: ";
do{
cin>>choice;
if (choice == 7)
{
system("pause");
exit (0);
}
}while (choice ==7);
}
void goSort(int newGrade[], const int NEW_GRADE )
{
for (int k = 1; k < NEW_GRADE; k++)
for (int i = 0; i <new_grade -1="" -="" mode="hold" /> if (newGrade[i] > newGrade[i +1]){
int temp = newGrade[i];
newGrade[i] = newGrade[i + 1];
newGrade[i + 1] = temp;
}
for (int count = 0; count < NEW_GRADE; count++)
{
cout<<"Grade "<<count<<" :"<<newGrade[count]<<"\n";
}
}