Results are out! Find what you need...fast. Get quick advice or join the chat
Hey there! Sign in to join this conversationNew here? Join for free to post

HELP!!-C++ Procedural Programming coursework

Announcements Posted on
Applying to Uni? Let Universities come to you. Click here to get your perfect place 20-10-2014
    • Thread Starter
    • 0 followers
    Offline

    ReputationRep:
    I am taking computing and networking and I need help with my program because it keeps no working could someone help plzzz.

    Im tryin to create a C++ program in visual basic that ask the user to enter the hours.

    the part i can't do ::confused: is make the program then calculate the amount of tax owed.

    here is my program:

    //VS8_multiple_if_examples_ex1.cpp
    //Using a combination of the 'IF' construction
    /* 'if' demo with relational and combinational operators */

    // file name pound_example.cpp
    // uses a statement with a pound sign
    #include "stdafx.h"
    #include<iostream>
    #include<iomanip>
    #include <conio.h>
    #include <stdio.h>

    using namespace std;
    unsigned char POUND_SIGN = 156;

    void main()
    {
    float gross_pay,net_pay,tax,rate_of_pa y;
    int hours;
    rate_of_pay=5.65;
    cout<<"How many hours did you work? \n";
    cin>>hours;

    if (hours<40)
    {
    //expressions go here

    }

    if ((hours>40)&&(hours<=50))
    {

    //expressions go here
    }

    if (hours>50)
    {

    //expressions go here
    }

    //format output
    cout << setprecision(2);
    cout.setf(ios::showpoint);
    cout.setf(ios::fixed);

    // output you results here

    if ((hours>40)&&(hours<=50))
    {

    //expressions go here
    }

    system("pause");
    return;
    }
    • Thread Starter
    • 0 followers
    Offline

    ReputationRep:
    plz anyone just giev feedback the submission deadline is 19/03/2012 this monday comin at 5AM.
    • 0 followers
    Offline

    ReputationRep:
    (Original post by J.2.B)
    Im tryin to create a C++ program in visual basic
    You can't create c++ programs in Visual basic, you need to go into visual studio and select visual c++ then empty projects. Hope this helps.

    LilcompT
    • 1 follower
    Offline

    ReputationRep:
    I think he means Visual Studio?

    What the code is suggesting is:

    1. Do something if the amount of hours entered is less than 40 hours.
    2. Do something if the amount of hours entered is between 41 and 50 hours.
    3. Do something if the amount of hours entered is greater than 50 hours.

    When printing:
    If the amount of hours entered is between 41 and 50 hours print something.

    You have:

    gross_pay
    net_pay
    tax
    rate_of_pay = 5.65
    hours

    so I am guessing you need to calculate a few things.

    // Calculate gross pay. Assumed to be per week.
    gross_pay = hours * rate_of_pay;

    // Calculate net pay. Assuming tax is already calculated somehow and is in the form of "tax paid per week".
    net_pay = gross_pay - tax;

    You need to set tax somewhere. You can set it just as you did for rate_of_pay.

    You could set tax as a percentage. E.g. 0.2 for 20%.
    In this case you would do:

    amount_of_tax_to_pay = gross_pay * tax;
    net_pay = gross_pay - amount_of_tax_to_pay;

    What I could do for your purposes is move the if statement to the bottom where you print the results and do the calculations there. This halves the number of if statements.

    Good luck.
    • 1 follower
    Offline

    ReputationRep:
    Code:
    //VS8_multiple_if_examples_ex1.cpp
    //Using a combination of the 'IF' construction
    /* 'if' demo with relational and combinational operators */
    
    // file name pound_example.cpp
    // uses a statement with a pound sign
    #include "stdafx.h"
    #include<iostream>
    #include<iomanip>
    #include <conio.h>
    #include <stdio.h>
    
    using namespace std;
    unsigned char POUND_SIGN = 156;
    
    void main()
    {
    float gross_pay,net_pay,tax,rate_of_pay;
    int hours;
    rate_of_pay=5.65;
    tax = 40; // random value for tax to be paid. Change or ask user to enter it as they entered their hours.
    cout<<"How many hours did you work? \n"; 
    cin>>hours;
    
    if (hours<40) 
    {
    // Calculate gross pay. Assumed to be per week.
    gross_pay = hours * rate_of_pay;
    
    // Calculate net pay. Assuming tax is already calculated somehow and is in the form of "tax paid per week". 
    net_pay = gross_pay - tax;
    
    cout << "Net Pay: " << net_pay;
    }
    
    if ((hours>40)&&(hours<=50)) 
    { 
    // Calculate gross pay. Assumed to be per week.
    gross_pay = hours * rate_of_pay;
    
    // Calculate net pay. Assuming tax is already calculated somehow and is in the form of "tax paid per week". 
    net_pay = gross_pay - tax;
    
    cout << "Net Pay: " << net_pay;
    }
    
    if (hours>50) 
    { 
    // Calculate gross pay. Assumed to be per week.
    gross_pay = hours * rate_of_pay;
    
    // Calculate net pay. Assuming tax is already calculated somehow and is in the form of "tax paid per week". 
    net_pay = gross_pay - tax;
    
    cout << "Net Pay: " << net_pay;	
    }
    
    //format output
    cout << setprecision(2);
    cout.setf(ios::showpoint);
    cout.setf(ios::fixed); 
    
    // output you results here
    
    if ((hours>40)&&(hours<=50))
    {
    cout << "We have printed non-formated output above.";	
    }
    
    cout << "We have printed non-formated output above.";
    
    system("pause");
    return;
    }

Reply

Submit reply

Register

Thanks for posting! You just need to create an account in order to submit the post
  1. this can't be left blank
    that username has been taken, please choose another Forgotten your password?
  2. this can't be left blank
    this email is already registered. Forgotten your password?
  3. this can't be left blank

    6 characters or longer with both numbers and letters is safer

  4. this can't be left empty
    your full birthday is required
  1. By joining you agree to our Ts and Cs, privacy policy and site rules

  2. Slide to join now Processing…

Updated: March 18, 2012
New on TSR

Personal statement help

Use our clever tool to create a PS you're proud of.

Article updates
Reputation gems:
You get these gems as you gain rep from other members for making good contributions and giving helpful advice.