J
Jordan Tiona
I can't get this code to work right. It seems to be skipping some of the cin
functions. Can someone help me with this?
ClassTrack.cpp:
#include <iostream>
#include "ClassTrack.h"
using namespace std;
const MAX_CLASSES = 12;
ClassType classes[MAX_CLASSES];
int classIndex;
int main(){
classIndex = 0;
bool quit = false;
int choice;
do {
cout << "Welcome to Class Tracker. What would you like to do? \n";
cout << "\t(1) Enter new Class Data \n";
cout << "\t(2) Print Class Data \n";
cout << "\t(3) Quit \n";
cin >> choice;
switch(choice){
case 1: EnterData();
break;
case 2: PrintData();
break;
case 3: quit = true;
break;
default: cout << "\nThat is an invalid choice. Please try
again\n";
system("cls");
break;
}
}while(quit == false);
return 0;
}
void EnterData(){
int choice;
system("cls");
cout << "How many classes do you wish to enter?\n";
cin >> choice;
for(int i = 0; i < choice; i++){
cout << "\n Name of class:";
cin.getline(classes[classIndex].nm, 25);
cout << "\n Class ID:";
cin >> classes[classIndex].id;
cout << "\n Class meets on:";
cin.getline(classes[classIndex].meets, 7);
cout << "\n Starting Time:";
cin.getline(classes[classIndex].start, 10);
cout << "\n Ending Time:";
cin.getline(classes[classIndex].end, 10);
cout << "\n Teacher:";
cin.getline(classes[classIndex].teacher, 25);
cout << "\n Number of students:";
cin >> classes[classIndex].numStudents;
classIndex++;
}
}
void PrintData(){
char choice[4];
system("cls");
cout << "Type the class ID of the class that you want\n";
cout << "to view, or type 'all' to print all of them.\n";
cin.getline(choice, 3);
if(choice == "all"){
for(int i = 0; i < classIndex; i++){
cout << classes.nm << endl;
cout << classes.id << endl;
cout << classes.meets << endl;
}
//Need to implement individual printing
}
ClassTrack.h:
void EnterData();
void PrintData();
struct ClassType {
char nm[25];
int id;
char meets[7];
char start[10];
char end[10];
char teacher[25];
int numStudents;
};
Please help.
functions. Can someone help me with this?
ClassTrack.cpp:
#include <iostream>
#include "ClassTrack.h"
using namespace std;
const MAX_CLASSES = 12;
ClassType classes[MAX_CLASSES];
int classIndex;
int main(){
classIndex = 0;
bool quit = false;
int choice;
do {
cout << "Welcome to Class Tracker. What would you like to do? \n";
cout << "\t(1) Enter new Class Data \n";
cout << "\t(2) Print Class Data \n";
cout << "\t(3) Quit \n";
cin >> choice;
switch(choice){
case 1: EnterData();
break;
case 2: PrintData();
break;
case 3: quit = true;
break;
default: cout << "\nThat is an invalid choice. Please try
again\n";
system("cls");
break;
}
}while(quit == false);
return 0;
}
void EnterData(){
int choice;
system("cls");
cout << "How many classes do you wish to enter?\n";
cin >> choice;
for(int i = 0; i < choice; i++){
cout << "\n Name of class:";
cin.getline(classes[classIndex].nm, 25);
cout << "\n Class ID:";
cin >> classes[classIndex].id;
cout << "\n Class meets on:";
cin.getline(classes[classIndex].meets, 7);
cout << "\n Starting Time:";
cin.getline(classes[classIndex].start, 10);
cout << "\n Ending Time:";
cin.getline(classes[classIndex].end, 10);
cout << "\n Teacher:";
cin.getline(classes[classIndex].teacher, 25);
cout << "\n Number of students:";
cin >> classes[classIndex].numStudents;
classIndex++;
}
}
void PrintData(){
char choice[4];
system("cls");
cout << "Type the class ID of the class that you want\n";
cout << "to view, or type 'all' to print all of them.\n";
cin.getline(choice, 3);
if(choice == "all"){
for(int i = 0; i < classIndex; i++){
cout << classes.nm << endl;
cout << classes.id << endl;
cout << classes.meets << endl;
}
//Need to implement individual printing
}
ClassTrack.h:
void EnterData();
void PrintData();
struct ClassType {
char nm[25];
int id;
char meets[7];
char start[10];
char end[10];
char teacher[25];
int numStudents;
};
Please help.