The following code compiles just fine:
However, when it reaches the bolded part of the function, it goes straight to the system("PAUSE"). Is there something wrong with the code that I'm not seeing? Or is it a problem somewhere else?Code:#include <iostream>
#include <stdlib.h>
#include <wincon.h>
using namespace std;
class course
{
public:
int nHour;
char cGrade;
int nMaxPoints;
int nCurrentPoints;
char CourseName[255];
};
course x[25];
int main();
//function to add a new a course
void addcourse()
{
int a;
a = 0;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN | FOREGROUND_INTENSITY);
std::cout<<"\nPlease enter the course name:";
std::cin>>x[a].CourseName[255];
std::cout<<"\nPlease enter the hour you have this class:";
std::cin>>x[a].nHour;
a++;
std::cout<<"\n";
system("PAUSE");
main();
}
//function to read courses
void readcourse()
{
int s;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_RED);
std::cout<<"\nEnter the course hour to find:";
std::cin>>s;
std::cout<<"Course Name:\n" << x[s].CourseName[255];
std::cout<<"\nCourse Hour:\n" << x[s].nHour;
system("PAUSE");
main();
}
//main function to find out options
int main()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_BLUE);
std::cout<<":::::::::: ::::::::::\n"
<<":::::::::: G R A D E K E E P E R ::::::::::\n"
<<":::::::::: ::::::::::\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE);
std::cout<<"\n\n\nEnter '1' to make a new a course, '2' to read an existing course!";
int choice;
std::cin>>choice;
int loop=0;
while(loop==0)
{
if(choice==1)
{
addcourse();
loop++;
}
if(choice==2)
{
readcourse();
loop++;
}
}
return 0;
system("PAUSE");
}