The Student Room Group

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_pay;
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;
}
Reply 1
plz anyone just giev feedback the submission deadline is 19/03/2012 this monday comin at 5AM.
Reply 2
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
Reply 3
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.
Reply 4


//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;
}
(edited 12 years ago)

Quick Reply

Latest