Thread: Advice to make my programming better(beginner programmer)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    34

    Advice to make my programming better(beginner programmer)

    Hello I am a fairly new at programming and have little experience with programming beyond the tutorials on this website(which I think I am on the 15th) and I have been messing around with a few programs that they have had in the the tutorials and expanding them and I was just wondering if there is any bad habits, things I could do to make my programs more organized, or anything else that I should try to fix now before I get to use to programming like that. One of the programs I have expanded on was in the tutorial about typecasting(lesson 11) and was showing how you could turn numbers into ASCII characters. I expanded on the program by giving an option to search for a certain number's character or to show all of the ASCII numbers. Here is what the program looks like
    Code:
    #include <iostream>
    
    
    using namespace std;
    
    int allchar()//prints all ASCII characters
    {
        int x = 0;//sets x to 0; allows for multiple printings of the ASCII characters
      while(x < 256) {
        cout<< x <<". "<< (char)x <<" ";
        x=x+1;
        //Note the use of the int version of x to
        // output a number and the use of (char) to
        // typecast the x into a character
        // which outputs the ASCII character that
        // corresponds to the current number
      }
      return 0;
    }
    int picked_char()//User inputs the number to find which character it is
    {
        cout<<"Please enter in the characters number you want to find.\n";
        int character;
        cin>>character;
        cin.ignore();
        character=character;
        cout<<character<<". "<< (char)character <<" ";
        return 0;
    
    
    }
    
    
    
    
    int main()
    {
        int again=1;//runs program again
        while(again == 1){
    
    
            int choice;//user input for list of ascII or certain one
            int letter;//uesr input for which character to search
            int again_repeat = 1;//makes sure correct input in the while(again_repeat)
            int repeat=1;//repeats while(again ==1) statement till correct input is put in
            int program_repeat;//input to control if program repeats
            while(repeat == 1){
                cout<<"Do you want a list of ASCII characters(press 1)\n";
                cout<<"or search for a certain one(press 2?\n";
                cout<<"\n";
                cin>>choice;
                cin.ignore();
                if(choice == 1){
                    allchar();
                    cout<<"\n";
                    cout<<"\n";
                    choice = 0;
                    repeat = 0;
    
    
                }
                else if (choice == 2){
                    picked_char();
                    cout<<"\n";
                    cout<<"\n";
                    choice = 0;
                    repeat = 0;
                }
                else{
                    cout<<"Invaild Entry. Please re-enter choice.\n";
                    cout<<"\n";
                    repeat = 1;
                }
            }
            cout<<"If you want to search for another ASCII character press 1.\n";
            cout<<"If you want to exit this program press 2.\n\n";
            while(again_repeat == 1){
                cin>>program_repeat;
                cin.ignore();
                cout<<"\n\n";
                if(program_repeat==1){
                    again=1;
                    again_repeat = 0;
                }
                else if(program_repeat==2){
                    again_repeat = 0;
                    again=0;
                }
                else{
                    cout<<"Invaild Entry. Please re_enter choice.\n";
                }
            }
        }
        return 0;
    }
    If any of you have any suggestions on things that might improve my programming now so I will not develop bad programming habits. Oh also sorry if the variables have names that might not make sense could not think of other names for them in the moment.
    Last edited by thadis_4; 12-11-2011 at 06:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advice for new C programmer re Windows
    By willsteele in forum Windows Programming
    Replies: 5
    Last Post: 11-25-2010, 02:04 PM
  2. Novice Programmer Humbly Requests Job Seeking Advice
    By steals10304 in forum General Discussions
    Replies: 7
    Last Post: 10-20-2009, 12:12 PM
  3. Fortran programmer new to c++. Looking for general advice.
    By Duff-Man in forum C++ Programming
    Replies: 12
    Last Post: 10-14-2009, 12:33 AM
  4. What game programmer should I be? need some advice.
    By m3rk in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 04-20-2009, 11:12 PM
  5. Any beginner C++ programmer wants to.....
    By incognito in forum C++ Programming
    Replies: 5
    Last Post: 12-06-2001, 08:15 AM