#include #include #include #include #include #include #include //macros #define LOCATE(r, c) GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);csbiInfo.dwCursorPosition.X = c;csbiInfo.dwCursorPosition.Y = r; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), csbiInfo.dwCursorPosition); using namespace std; //prototyping void paintMenu(), getChoice(); void car(string carName); void paintCarMenu(string carName), getCarChoice(); //global varable char choice; int carChoice; vector option; CONSOLE_SCREEN_BUFFER_INFO csbiInfo; int main() { do { paintMenu(); getChoice(); }while(choice != '0'); system("CLS"); return 0; } void paintMenu() { system("CLS"); LOCATE(0,35); puts("MAIN MENU"); LOCATE(2,0); puts("\t1. Cars"); puts("\t2. Jobs"); puts("\t3. Programs"); puts("\n\r\t0. Quit"); LOCATE(23,0); printf("Enter your choice (0,1,2,3) =>"); } void getChoice() { scanf("%c",&choice); switch(choice) { case '1' : car(""); break; //case '2' : jobs(); break; //case '3' : programs(); break; case '0' : break; default : LOCATE(23, 40); printf("Invalid Entry\n\r"); system("PAUSE"); } fflush(stdin); } void car(string carName) { do { paintCarMenu(carName); getCarChoice(); }while(carChoice != '0'); system("CLS"); } void paintCarMenu(string carName) { option.clear(); string line; ifstream carList; system("CLS"); LOCATE(0,35); if(carName == "") { puts("Car Menu"); carList.open("data/car"); } else { cout << carName << " Menu"; carList.open(carName.insert(0,"data/").c_str()); } LOCATE(2,0); for(int k = 1; !carList.eof(); k++) { getline(carList,line); //gets one line from text file as String if(line[0] == '_') { do { cout << line << "\n\r"; getline(carList,line); } while(!carList.eof()); cout << line << "\n\r"; return; } cout << "\n\r\t" << k << " " << line; option.push_back(line); } puts("\n\n\r\t0. Quit"); LOCATE(23,0); printf("Enter your choice =>"); carList.close(); } void getCarChoice() { cin.ignore(); fflush(stdin); scanf("%i",&carChoice); cout << carChoice; for( int j = 0; j < option.size(); j++) { if( carChoice == 0) { return; } else if(carChoice == j + 1) { car(option.at(j)); return; } } { LOCATE(23, 40); printf("Invalid Entry\n\r"); system("PAUSE"); getCarChoice(); //break; } fflush(stdin); }