68.1k views
4 votes
Write a C++ program in which you declare variables that will hold an hourly wage, a number of hours worked, and a withholding percentage. Prompt the user to enter values for each of these fields. Compute and display net weekly pay, which is calculated as hours times rate, minus the percentage of the gross pay that is withholding.

User Ron
by
6.9k points

1 Answer

4 votes

Answer:

C++ program: -

//header files

#include <iostream>

//namespace for using input and output stream

using namespace std;

//main function

int main()

{

//declaring the variables

float wg,hrs,pt,np;

//prompt the user to enter the hourly wage

cout<<"Please enter the hourly wage: ";

//storing the value

cin>>wg;

//prompt the user to enter the working hours

cout<<"Please enter the hours worked: ";

//storing the values

cin>>hrs;

//prompt the user to enter to enter the percentage

cout<<"Please enter the withholding percentage: ";

//storing the value

cin>>pt;

//calculating the next week pay

np= (hrs*wg*7)- (hrs*wg*7*pt/100);

//displaying the next week pay

cout<<"Net weekly pay: "<<np;

//return statement

return 0;

}

Step-by-step explanation:

In the above program, the variable used are given below: -

float wg,hrs,pt,np;

wg:- To store the hourly wage

hrs:- To store the working hours

pt:- To store the percentage

np:- To store the next week payment

The input and the output streams that are used to input and storing the values are cin and cout.

To calculate the next week payment below formula is used:-

np= (hrs*wg*7)- (hrs*wg*7*pt/100);

Output :-

Please enter the hourly wage: 100

Please enter the hours worked: 8

Please enter the withholding percentage: 5

Net weekly pay: 5320

User Nitish Parkar
by
7.0k points