Suggestions on making this program better

This is a discussion on Suggestions on making this program better within the C++ Programming forums, part of the General Programming Boards category; Hi I am a beginner and I made this utility for work to keep all my forklifts tires and bearings ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    10

    Smile Suggestions on making this program better

    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
    Attached Files Attached Files

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    Right well sorry but you have to fix up your formatting first, those open close end braces are crazy, i have not seen that style ever and it is not nice, remove all the yards of whitespace and clean and tighten things up, you can find plenty of info on good indentation on the web or just by looking at good quality code snippets.

    As to the quality of the code it's hard to say: because its difficult to read !

    I had a look at source file to see if the layout might just be getting messed up over the web... but no sorry

    If you tidy it up you are more likely to attract advice of the sort that you actually came looking for
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    10
    I google indentation which style is used the most?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,169
    Quote Originally Posted by fredz0003
    I google indentation which style is used the most?
    Allman and K&R, and minor variations thereof, are commonly used.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by fredz0003 View Post
    I google indentation which style is used the most?
    How to Indent Properly
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  6. #6
    Registered User
    Join Date
    Dec 2010
    Posts
    10

    Re:Suggestion on making this program better

    Apologies for the bad formatting on my program and thanks for letting me know so I took care of that I think I hope is readable now, it was painful to go line by line and now that I fixed it I see it looks way better.
    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);
    }
    Attached Files Attached Files

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,169
    Here is how I might have formatted your program:
    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);
    }
    My observations:
    • There is no reason for response is a global variable; prefer local variables and pass them around if needed.
    • Your global main function is well over 250 lines, even after I removed some extra blank lines; functions should do one thing and do it well.
    • You have code that is repeated time and time again with what looks like copy and paste; this is crying out loud to be moved into a function or otherwise re-arranged.
    • Avoid magic numbers. We can see what those numbers mean from the menu text, but when the menu text is way before the places where these numbers are used, it becomes more difficult to understand what is what. Using named constants would help.
    • Your excessive use of endl is not necessarily wrong, but you don't really need to flush the output buffer all the time. Just use '\n' and reserve endl to when you want to print a newline and flush the output buffer.


    EDIT:
    On that last point, here is an example, where this:
    Code:
    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;
    could become:
    Code:
    cout << "               Reach Truck Tires and Bearings\n\n"
            "               Load Wheel.......................632052GB\n"
            "                    >>Load Wheel Bearing .......441-130\n"
            "               Steered Idler Wheel..............632-078/007\n"
            "                    >>Bearing(Steered Idler)....44-128\n"
            "               Drive Wheel Assy.................828-003-339/101\n"
            "                    >>Drive Tire only ..........632-131/001\n"
            "                    >>Hub, Drive Wheel..........828-003-073\n\n"
            "               Main menu 1 or 6 to quit program"
         << endl;
    Last edited by laserlight; 10-06-2011 at 09:38 PM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Dec 2010
    Posts
    10

    Re: Suggestion on making this program better

    Thanks laserlight I will work on the program based on your obseevation
    and I did noticed the better indentation format I will work on that as well, thanks for the time and reading my code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Suggestions for my Check Book program
    By Nor in forum C++ Programming
    Replies: 2
    Last Post: 11-17-2008, 06:44 PM
  2. First Program - would like improvement suggestions
    By Venicia in forum C++ Programming
    Replies: 2
    Last Post: 05-24-2007, 10:53 AM
  3. Hi, Suggestions on my program please..
    By Siggy in forum C++ Programming
    Replies: 44
    Last Post: 11-23-2004, 10:55 PM
  4. any suggestions on how to make this program smaller?
    By bajan_elf in forum C++ Programming
    Replies: 4
    Last Post: 05-12-2003, 04:24 AM
  5. need some suggestions for making 3D game
    By SuperNewbie in forum Game Programming
    Replies: 4
    Last Post: 01-05-2003, 01:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21