Please, i need a teacher to help me out...i am at the intro stage and i was wondering if someone would walk me through this please..i would appreciate it.

Mr. Clark employs students who are exempt from taxes and others who are not. Write a program that will calculate and display weekly wages. If an employee is not exempt, 18% will be deducted from gross wages, otherwise “NO TAXES DEDUCTED” will be displayed.

Two program runs are shown below:
Enter hours worked: 45
Enter hourly rate: 10.00
Exempt (Y/N)? Y
Gross wages = \$475.00
NO TAXES DEDUCTED
Enter hours worked: 20

Enter hourly rate: 4.00
Exempt (Y/N)? N
Gross wages = \$80.00
Wages after taxes = \$65.60

Answered by vmanes 1,165 in a post from

You should make an attempt to solve the problem first. Then, point out what's giving you difficulty, and we will try to help you find the solution.

For your problem, start by writing out the steps you would take to do this by hand. What input do you need, what …

You are missing some brackets. statements that are two or more lines require brackets, like this:

if (Exempt == 'Y' )
{
cout << "Gross wages = " << (hoursWorked*hourlyRate) << endl;
cout << "NO TAXES DEDUCTED";
{
else if (Exempt == 'N')
{
cout << "Gross … This post has no text-based content.

All 9 Replies

You should make an attempt to solve the problem first. Then, point out what's giving you difficulty, and we will try to help you find the solution.

For your problem, start by writing out the steps you would take to do this by hand. What input do you need, what decision do you need to make based on that input, what calculations do you do?

this is what i have so far but it dont work

#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
double hoursWorked, hourlyRate, grossWages;
char Exempt;

cout << "Enter hours worked: ";
cin >> hoursWorked;
cout << "Enter hourly rate: ";
cin >> hourlyRate;
cout << "Exempt (Y/N)? ";
cin >> Exempt;

cout << "Enter hours worked: ";
cin >> hoursWorked;
cout << "Enter hourly rate: ";
cin >> hourlyRate;
cout << "Exempt (Y/N)? ";
cin >> Exempt;

if (Exempt == 'Y' )
cout << "Gross wages = " << (hoursWorked*hourlyRate) << endl;
cout << "NO TAXES DEDUCTED";

else if (Exempt == 'N')
cout << "Gross wages = " << (hoursWorked*hourlyRate) << endl;
cout << "Wages after taxes = " << (hoursWorked*hourlyRate)-((hoursWorked*hourlyRate))*0.18 << endl;

system("PAUSE");
return 0;
}

You are missing some brackets. statements that are two or more lines require brackets, like this:

if (Exempt == 'Y' )
{
cout << "Gross wages = " << (hoursWorked*hourlyRate) << endl;
cout << "NO TAXES DEDUCTED";
{
else if (Exempt == 'N')
{
cout << "Gross wages = " << (hoursWorked*hourlyRate) << endl;
cout << "Wages after taxes = " << (hoursWorked*hourlyRate)-((hoursWorked*hourlyRate))*0.18 << endl;
} This post has no text-based content.

it work now ..............

Did you realize that you are taking in your 3 data elements twice?

And that the 2nd 'take in' set of data ... over-write the first?

Also ... do you realize that in math:

For any value a,

( a - 0.18*a )
=
a * (1 - 0.18)
=
a * 0.82

So your calculation can be a little more efficently coded ... yes?

i dont quite understand david

Maybe this will give you some more ideas ...

// beginnerPayProgram.cpp //  // 2014-03-02 //

// Note the added loop, comments, keeping cin stream 'flushed as we go'
// and .. the demo of one simple way for validation, etc...

#include <iostream>
#include <iomanip> // re. setprecision( ), setw( ), etc ...
#include <cctype> // re. toupper ...

using namespace std;

int main()
{
bool more = true;

cout << setprecision(2) << fixed; // show 2 decimal places

while( more ) // top while loop test ... loop until more = false
{
cout << "Enter hours worked :  ";
double hoursWorked;
if( cin >> hoursWorked )
{
cout << "Enter hourly rate  :  ";
double hourlyRate;
if( cin >> hourlyRate )
{
cout << "Exempt (Y/N)       :  ";
char exempt ;
cin >> exempt;

exempt = toupper( exempt );
if( exempt != 'Y' && exempt != 'N' )
{
cout << "You did not enter 'Y' or 'N' ... \n";
continue; // from top 'while loop test' *NOW*
}

// Ok ... all good so far ... but good to ...
// 'flush' cin stream /  'eat' the '\n' char left,
// that IS still there at the end of the cin stream

while( cin.get() != '\n' ) ; // exits when eats '\n' char left above

// Now ... calculate and report

cout << "\nGross wages        =  \$" << setw( 8 )
<< hoursWorked * hourlyRate << endl;

if( exempt == 'Y' )
cout << "NO TAXES DEDUCTED\n" ;

else
cout << "Wages after taxes  =  \$" << setw( 8 )
<< (hoursWorked*hourlyRate) * 0.82
<< endl;
}
}
else
cout << "\nThere was a data entry error ...\n";

// clear the cin error flags ...
cin.clear();

// 'flush' the cin stream to ensure 'wait for data' entry ...
// i.e. ensure that the program will wait for reply below ...
cin.sync();

cout << "\nTry again (y/n) ? ";

more = ( toupper( reply ) != 'N' ) ; // defaults to 'Yes'

// exits this below while loop AFTER eats '\n' char left above
while( cin.get() != '\n' ) ;
}

return 0;
}

I'm new and I'm interested in this topic. Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.