Escolar Documentos
Profissional Documentos
Cultura Documentos
The Program
//
//
//
//
//
#include <stdio.h>
void main()
{
double salary, tax, health, NIS;
int i;
// looping variable in the for statement
for (i = 1; i <= 4; i += 1)
{
printf_s("Enter salary \n");
scanf_s ("%lf", &salary);
if (salary > 50000)
{
tax = 0.35 * salary;
health = 0.05 * salary;
NIS = 0.02 * salary;
}
else
{
tax = 0.28 * salary;
health = 0.035 * salary;
NIS = 0.015 * salary;
}
The Solution
The solution should have the following format:
DAY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
SALARY
0.01
0.02
0.04
0.08
0.16
0.32
0.64
1.28
2.56
5.12
10.24
20.48
40.96
81.92
The Program
//
//
//
//
//
//
#include <stdio.h>
void main()
{
int day = 1;
double salary = 0.01;
printf_s("DAY
Sentinel-Controlled loops
The Program
//
//
//
//
#include <stdio.h>
void main()
{
int grade;
double sum = 0;
double average;
int num = 0;
//
//
//
//
input
to hold the sum of the grades
to hold the average
to hold the number of grades
Must read
before the
loop
Read
again at
end of
loop
Exercise
Write a program which uses a sentinel
controlled loop to enter a set of alphabetic
characters, and to output the number of
vowels and the number of consonants entered.
Use the period as the sentinel to halt the
looping.
The Program
//
//
//
//
//
//
//
//
#include <stdio.h>
void main()
{
int id;
char program;
int numCredits;
double cost, totCost = 0;
char response = 'Y';
char dummy;
// To catch the carriage return
\n");
return;
}
totCost += cost;
switch (program)
{
case 'i':
case 'I':
break;
case 'e':
case 'E':
break;
case 'm':
case 'M':
break;
default:
Exercise
This question deals with simulating a cash register at a grocery store. For each of a set of items purchased
by a customer, you are to enter the item code of the item (int), the number of units of the item purchased
and the unit price of the item. Your program should then determine and display the total for the item
purchased. Your program should also accumulate these totals in order to determine the grand total payable
by the customer. The grand total payable by the customer should also be displayed.
You do not know how many items are purchased by the customer. Your procedure must use a responsecontrolled loop to handle the looping.
Use the following data when running your program:
Item Code
Num. Units
Unit Price
1250
1376
2872
5839
8586
5834
5
7
3
2
2
3
12.50
3.75
2.75
12.87
89.50
9.45
Nested Loops
.
.
.
This loop is
nested
The Output
After processing the data for each customer,
your program should ask if there are any more
customers. If the response is Y, then go on to
process the next customer.
//
//
//
//
//
#include <stdio.h>
#include <ctype.h>
void main()
{
int itemCode;
int numUnits;
double unitPrice, extPrice, totalPrice;
char response1 = 'Y';
// to control outer loop
char response2;
// to control inner loop
char dummy;
// to catch carriage return
response2 = toupper(response2);
}
} // end of inner loop
// Print total for customer
printf_s("Total owing = %8.2f \n\n", totalPrice);
ASSIGNMENT