Assignment 4 Fop
Assignment 4 Fop
Question 1:
A person invests $1000.00 in a savings account yielding 5% interest. Assuming that all interest is left on
deposit in the account, using while loop calculate and print the amount of money in the account at the
end of each year for 10 years. Use the following formula for determining these amounts:
𝑎 = 𝑝 (1 + 𝑟) 𝑛
Where
Solution:
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
//Declaring variables
int n, p, r, a;
//Initializing values
Solution:
#include <stdio.h>
#include <math.h>
int main()
{
//Declaring variables
int x, y, Value, Sum = 0;
//Calculating sum
printf("\nThe Sum of integers is %d. ", Sum);
Question 3:
Write a program that calculates and prints the average of several integers. Assume the last value read
with scanf is the sentinel 9999. A typical input sequence might be
10 8 11 7 9 9999
indicating that the average of all the values preceding 9999 is to be calculated.
Solution:
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
//Declaring variables
int i, count = 0, sum = 0;
float Average;
}
else
{
sum += i;
}
count++;
}
//Calculating Average of integers
Average = sum / count;
Question 4:
Write a program that calculates and prints the sum of the even integers from 2 to 30.
Solution:
#include <stdio.h>
#include <math.h>
int main()
{
//Declaring variables
int i, Sum = 0;
Question 5:
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who
receive a fixed hourly wage for up to the first 40 hours they work and “time-and-a-half”—i.e., 1.5 times
their hourly wage—for overtime hours worked), commission workers (who receive $250 plus 5.7% of
their gross weekly sales), or pieceworkers (who receive a fixed amount of money for each of the items
they produce—each pieceworker in this company works on only one type of item). Write a program to
compute the weekly pay for each employee. You do not know the number of employees in advance.
Each type of employee has its own pay code: Managers have pay code 1, hourly workers have code 2,
commission workers have code 3 and pieceworkers have code 4. Use a switch to compute each
employee’s pay based on that employee’s pay code. Within the switch, prompt the user (i.e., the payroll
clerk) to enter the appropriate facts your program needs to calculate each employee’s pay based on that
employee’s pay code. [Note: You can input values of type double using the conversion specifier %lf with
scanf.]
Solution:
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
//Declaring variables
int Paycode = 0, hours, items;
double Weekly_salary, Hourly_salary, Gross_sales, Pay_per_item, Total_pay;
case 2:
//Salary of Hourly Worker
printf("You have selected Hourly Worker.\nEnter Hourly Salary:$");
scanf_s("%lf", &Hourly_salary);
case 3:
//Salary of Commission Worker
printf("You have selected Commission Worker.\nEnter Gross Sales:$");
scanf_s("%lf", &Gross_sales);
Total_pay = 250 + Gross_sales * 0.057;
break;
case 4:
//Salary of Pieceworker
printf("You have selected Pieceworker.\nEnter Number of Items
Produced by Pieceworker:");
scanf_s("%d", &items);
Total_pay = items*Pay_per_item;
break;
default:
//if paycode is invalid
printf("You have entered an INVALID PAYCODE!\n");
Total_pay = 0;
break;
}
//Printing of Paycode
printf("The Total Pay of the Worker is:$%.2lf\n", Total_pay);
printf("\nEnter Paycode for next Employee(-1 to Exit): ");
scanf_s("%d", &Paycode);
}