// Assignment 3 solution
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::fixed);
cout.precision(1 );
float hours, gross, tax, net, rate;
cout << "Enter hours worked: " ;
cin >> hours;
if (hours > 40 ) {
gross = 40 * 12 + (hours - 40 ) * 16 ;
}
else {
gross = hours * 12 ;
}
cout << "Gross pay is $" << gross << " \n " ;
if (gross > 400 ) {
rate = .12 ;
}
else {
rate = .10 ;
}
tax = gross * rate;
cout << "Your tax is $" << tax << " (" << rate*100 << "%) \n " ;
net = gross - tax;
cout << "Your net is $" << net << " \n " ;
return 0 ;
}
// Loop example. This prints the integers from 1 up to
// (and including) the number the user types.
#include <iostream>
using namespace std;
int main()
{
int n=0 , i=1 ;
cout << "Enter an integer: " ;
cin >> n;
while (i <= n)
{
cout << i << " \n " ;
i = i + 1 ;
}
return 0 ;
}
// Quiz average, dropping lowest
#include <iostream>
using namespace std;
int main()
{
float q1=0 , q2=0 , q3=0 ;
float average;
float dropped;
cout << "Enter quiz 1: " ;
cin >> q1;
cout << "Enter quiz 2: " ;
cin >> q2;
cout << "Enter quiz 3: " ;
cin >> q3;
// Drop the lowest
if (q1 <= q2 && q1 <= q3) {
dropped = q1;
}
else if (q2 <= q3 && q2 <= q1) {
dropped = q2;
}
else {
dropped = q3;
}
cout << "Dropping lowest: " << dropped << endl;
average = (q1 + q2 + q3 - dropped) / 2 ;
cout << "Average is " << average << endl;
return 0 ;
}
© 2012 Christopher League · some rights reserved ·
CC by-sa