HELP!!-C++ Procedural Programming coursework

University course discussion for computer science and IT.

Announcements Posted on
IMPORTANT: You must wait until midnight (morning exams)/4.30AM (afternoon exams) to discuss Edexcel exams and until 1pm/6pm the following day for STEP and IB exams. Please read before posting, including for rules for practical and oral exams. 28-04-2013
Sign in to Reply
  1. J.2.B's Avatar
    • New Member
    • Posts: 8
    HELP!!-C++ Procedural Programming coursework
    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;
    }
  2. J.2.B's Avatar
    • New Member
    • Posts: 8
    Re: HELP!!-C++ Procedural Programming coursework
    plz anyone just giev feedback the submission deadline is 19/03/2012 this monday comin at 5AM.
  3. LilcompT's Avatar
    • Junior Member
    • Posts: 38
    Re: HELP!!-C++ Procedural Programming coursework
    (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
  4. SpamTheMan's Avatar
    • Junior Member
    • Posts: 69
    Re: HELP!!-C++ Procedural Programming coursework
    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.
  5. SpamTheMan's Avatar
    • Junior Member
    • Posts: 69
    Re: HELP!!-C++ Procedural Programming coursework
    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;
    }
    Last edited by SpamTheMan; 18-03-2012 at 13:48. Reason: set tax
Sign in to Reply
Share this discussion:  
Article updates
Moderators

We have a brilliant team of more than 60 volunteers looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Reputation gems:
The Reputation gems seen here indicate how well reputed the user is, red gem indicate negative reputation and green indicates a good rep.
Post rating score:
These scores show if a post has been positively or negatively rated by our members.