Intro. To C Programming
by
Yanique Campbell
An assignment submitted in partial fulfillment of the requirements for the course Intro. To C Programming
Instructor: Mr. Rohan Simpson
Date: March 18, 2014
Department of Communication and Information Technology
Bethlehem Moravian College.
Question 1
A program is required to read a customer’s name, a purchase amount and a tax code. The tax code has been validated and will be one of the following:
• 0 tax exempt (0%)
• 1 state sales tax only (3%)
• 2 federal and state sales tax (5%)
• 3 special sales tax (7%)
The program must then compute the sales tax and the total amount due, and print the customer’s name, purchase amount, sales tax and total amount due.
Solution
#include <stdio.h>
#include <conio.h> int main ()
/*Nestes if statements*/
{
int taxcode; float pamount; float stax; float tamount; char name [30]; printf ("Enter name\n"); scanf ("%s", &name); printf ("Enter pamount\n"); scanf ("%f", &pamount); printf ("Enter a taxcode from(0-3)\n"); scanf ("%d", &taxcode); if (taxcode==0) { stax=pamount*0; tamount=pamount+stax; } else if (taxcode==1) { stax=pamount*0.03; tamount=pamount+stax; } else if (taxcode==2) { stax=pamount*0.05; tamount=pamount+stax; } else if (taxcode==3) { stax=pamount*0.07; tamount=pamount+stax; } printf ("Name is:%s\n", name); printf ("Total amount is:%f\n", tamount);