Like Tree4Likes
  • 1 Post By jimblumberg
  • 1 Post By whiteflags
  • 2 Post By Cat

Hint for an old dude

This is a discussion on Hint for an old dude within the C++ Programming forums, part of the General Programming Boards category; I am an "old dude" who became frustrated with my current career and decided to go back to school to ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    11

    Hint for an old dude

    I am an "old dude" who became frustrated with my current career and decided to go back to school to make a career change. I am in my second semester and in a C++ programming class. My question involves an assignment that has already been turned in for grading, and is not required as part of my assignment, but I am curious.

    My code needs some work, but where I am curious is the end. How do I get the program to repeat after the system pause? I read about loops and whiles, but maybe I am missing something. After pressing "any key", my program terminates, but how would I get it to re-start from the beginning?

    BTW, I used the "code tags", but apparently I used them wrong because it does not have the correct indentation. Please recall that I am an old dude trying to learn all of this stuff. I will eventually get. Please bear with me.

    Code:
    //Travis Bryant
    //CPT-168-A01
    //Calculate the Gross Pay Program
    #include
    <iostream>
    using
    namespace std;
    int
     main()
    {
    	system(
    "color f0");
    	cout<<
    "\t\t\t***********************************"<<endl;
    	cout<<
    "\t\t\t*          Travis Bryant          *"<<endl;
    	cout<<
    "\t\t\t*           CPT-168-A01           *"<<endl;
    	cout<<
    "\t\t\t*     Calculate the Gross Pay     *"<<endl;
    	cout<<
    "\t\t\t***********************************"<<endl;
    	
    double hrswrkd = 0.0, hrlyrat = 0.0, yrswrkd = 0.0,notpay = 0.0, otpay = 0.0, bnspay = 0.0, pay1 = 0.0, totpay = 0.0; 
    	cout<<
    "Please Enter Hours Worked: ";
    	cin>>hrswrkd;
    	cout<<
    "Please Enter Hourly Pay Rate: ";
    	cin>>hrlyrat;
    	
    if (hrswrkd > 40)
    		notpay = hrlyrat * 40, otpay = (hrswrkd - 40) * 1.5 * hrlyrat, pay1 = otpay + notpay;
    	
    else
    		pay1 = hrswrkd * hrlyrat;
    	cout<<
    "Gross Pay: $"<<pay1<<endl<<endl;
    	cout<<
    "Please Enter Years of Service ";
    	cin>>yrswrkd;
    	
    if (yrswrkd >= 1 && yrswrkd <= 5)
    		bnspay = pay1 * .05;
    	
    else
    		
    if (yrswrkd >= 6 && yrswrkd <= 9)
    			bnspay = pay1 * .10;
    		
    else
    			
    if (yrswrkd == 10)
    				bnspay = pay1 * .15;
    			
    else
    				
    if (yrswrkd > 10)
    					bnspay = pay1 * .20;
    				
    //endif
    			
    //endif
    		
    //endif
    	
    //endif
    	cout<<
    "Employee Longevity Bonus: $"<<bnspay<<endl<<endl;
    	totpay = pay1 + bnspay;
    	cout<<
    "Total Employee Pay: $"<<totpay<<endl<<endl;
    	cout<<
    "THANK YOU!!!"<<endl<<endl;
    	system(
    "pause");
    	
    return 0;
    }
     
     
    

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,560
    You may want to study up on the various loop constructs like do/while, while, and for(;.

    As far as your problems with posting, be sure to as post plain text.

    Jim
    Tdawg75 likes this.

  3. #3
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,526
    My code needs some work, but where I am curious is the end. How do I get the program to repeat after the system pause? I read about loops and whiles, but maybe I am missing something. After pressing "any key", my program terminates, but how would I get it to re-start from the beginning?
    Programs that are capable of doing that are structured to make that work.

    You said you read about loops. Repeating an entire program is just another loop.
    Code:
    while not ready to quit:
      calculate the gross pay
      find out if they are ready to quit
    end while
    quit
    You must plan out the flow of the program as much as the individual instructions, until you get to such a point that you are comfortable writing it in language xyz.
    Tdawg75 likes this.

  4. #4
    Registered User
    Join Date
    Mar 2013
    Posts
    11
    Quote Originally Posted by whiteflags View Post
    Programs that are capable of doing that are structured to make that work.

    You said you read about loops. Repeating an entire program is just another loop.
    Code:
    while not ready to quit:
      calculate the gross pay
      find out if they are ready to quit
    end while
    quit
    You must plan out the flow of the program as much as the individual instructions, until you get to such a point that you are comfortable writing it in language xyz.
    Ok, thank you both for your replies. Whiteflags, that is probably why he hasn't taught it to us yet (not that I recall anyway), but it just bugs me that it terminates every time.

  5. #5
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Also, for many good reasons (readability, maintainability, testability, reusability) try to break this down into separate functions, each of which has one 'job'.

    For example, I would break it down into four functions (not counting main which would become very short):
    * Display splash screen
    * Collect user input
    * Perform calculations
    * Display the calculation results

    If you wanted to repeat, you would just put a loop inside main() where these four functions were called until some termination condition occurred (e.g. the user chose to quit).
    Salem and Tdawg75 like this.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New dude needs simple help :P
    By XunTric in forum C++ Programming
    Replies: 8
    Last Post: 09-26-2005, 10:22 AM
  2. anyone here have capture the dude?
    By cozman in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 03-24-2002, 11:10 AM
  3. Who knows this is the real dude !!!!!!!!!!!!!!!!!!!!!!
    By tomkat in forum Windows Programming
    Replies: 8
    Last Post: 11-09-2001, 02:53 PM
  4. Who knows this ... is the real dude !
    By tomkat in forum C Programming
    Replies: 1
    Last Post: 11-02-2001, 05:52 PM
  5. Who knows this ... is the real dude !!!!!!!!!
    By tomkat in forum Windows Programming
    Replies: 0
    Last Post: 11-02-2001, 05:39 PM

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