Hi I am a beginner and I made this utility for work to keep all my forklifts tires and bearings at hand. It is basically a menu and you can choose from different forklifts to pull the different part numbers. However how can I implement a function to check for the input because it is repeating too many times. I tried to do it but it just printed a bunch of random numbers. Aso how I use a text file to keep the part numbers there and write new ones if I need to. Here's what I got so far.
Code:#include<iostream> #include<string> #include<limits> using namespace std; int response = 0; int main() { //Main screen cout << " +++++++++++++++++++++++++++++++++++++++++++++++++++++ " << endl; cout << " + Welcome to Tire Utility + " << endl; cout << " + Made by Fernando Balandran V1.0 + " << endl; cout << " + + "<<endl; cout << " + + "<< endl; cout << " + Press 1 for Menu + " << endl; cout << " + Press 6 to quit program + " << endl; cout << " +++++++++++++++++++++++++++++++++++++++++++++++++++++ " << endl; //Checks the input and clears cin bool quit2 = false; do { cin >> response; cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); if (response == 1) { cout << "Loading....." <<endl; quit2 = true; break; } if (response == 6) { break; } else { cout << "Invalid input. Try again: " <<endl; } } while(!quit2); bool quit = false; do { if (response == 1) { cout << " Press 1 to Return to Main Menu " << endl; cout << " Press 2 for Reach " << endl; cout << " Press 3 for Pacer " << endl; cout << " Press 4 for Transport " << endl; cout << " Press 5 for Order Picker " << endl; cout << " Press 6 to quit program " << endl; bool quit2 = false; do { cin >> response; cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); if (response <= 5) { cout << "Loading....." <<endl; quit2 = true; break; } if (response == 6) { quit2 = true; } else { cout << "Invalid input. Try again: " <<endl; } } while(!quit2); } if (response == 2) { cout << " Reach Truck Tires and Bearings " << endl; cout << endl; cout << " Load Wheel.......................632052GB" << endl; cout << " >>Load Wheel Bearing .......441-130" << endl; cout << " Steered Idler Wheel..............632-078/007" << endl; cout << " >>Bearing(Steered Idler)....44-128" << endl; cout << " Drive Wheel Assy.................828-003-339/101" <<endl; cout << " >>Drive Tire only ..........632-131/001" << endl; cout << " >>Hub, Drive Wheel..........828-003-073" << endl; cout << endl; cout << " Main menu 1 or 6 to quit program" << endl; bool quit2 = false; do { cin >> response; cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); if (response == 1) { cout << "Loading....." <<endl; quit2 = true; break; } if (response == 6) { break; } else { cout << "Invalid input. Try again: " <<endl; } } while(!quit2); } if (response == 3 ) { cout << " Pacer Drive Wheel" << endl; cout << " >>Tire, Rubber, Black, Standard......630-259/001"<<endl; cout << " >>Wheel, Hub.........................223-001-153/002" <<endl; cout << " >>Bolt, Tire, Drive..................828-004-578" << endl; cout << endl; cout << " Steering Wheel" << endl; cout << " >>Tire Black.........................632-099/002" <<endl; cout << " >>Hub, Machine.......................123-000-586"<< endl; cout << " >>Bearing, Cup.......................447-561"<< endl; cout << " >>Bearing, Roller....................447-085"<< endl; cout << " >>Seal...............................530-615"<< endl; cout << endl; cout << " Main menu 1 or 6 to quit program" << endl; bool quit2 = false; do { cin >> response; cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); if (response == 1) { cout << "Loading....." <<endl; quit2 = true; break; } if (response == 6) { break; } else { cout << "Invalid input. Try again: " <<endl; } } while(!quit2); } if (response == 4 ) { cout << " Transport Drive Wheel" << endl; cout << " >>Tire, Rubber, Black, Standard......1063760/001"<<endl; cout << " >>Wheel, Hub.........................1058946" <<endl; cout << endl; cout << " Load Wheels" << endl; cout << " 3 Wheel Kit...............................939-WHL/KITGL" <<endl; cout << endl; cout << " Split Wheel...............................632-076/007"<< endl; cout << " >>Bearing, Roller....................441-127"<< endl; cout << endl; cout << " Single Wheel..............................632069GB"<< endl; cout << " >>Bearing, Roller....................441-127" <<endl; cout << endl; cout << " Caster Assy...............................1019920" <<endl; cout << " >>Wheel..............................632421GB" << endl; cout << " Main menu 1 or 6 to quit program" << endl; bool quit2 = false; do { cin >> response; cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); if (response == 1) { cout << "Loading....." <<endl; quit2 = true; break; } if (response == 6) { break; } else { cout << "Invalid input. Try again: " <<endl; } } while(!quit2); } if (response == 5 ) { cout << " Order Picker Wheels" << endl; cout << " >>Drive Wheel........................114-018-513/001"<<endl; cout << endl; cout << " Load Wheel" << endl; cout << " >>Wheel, Poly........................632-156/003" << endl; cout << " >>Bearing, Ball......................441-30"<< endl; cout << " Main menu 1 or 6 to quit program" << endl; bool quit2 = false; do { cin >> response; cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); if (response == 1) { cout << "Loading....." <<endl; quit2 = true; break; } if (response == 6) { break; } else { cout << "Invalid input. Try again: " <<endl; } } while(!quit2); } if (response == 6 ) { cout << "Exiting program........"; quit = true; } } while (!quit); }
Thanks a lot for the help



LinkBack URL
About LinkBacks



