In: Computer Science
Write Program in C:
Write a program that: program starts; declares and initializes to 7.25% constant float variable NJSALES_TAX; declares and initializes to 1000 an integer variable total; declares and initializes to zero a float variable grand_total; prompt and input on new line total; calculate grand_total to equal total plus (total*NJSALES_TAX); if grand_total <= 1000 print on new line “Grand total is less than or equal to 1000 it is $” and the grand_total to two decimal places; else if grand_total between 1000 <= 2000 print on new line “Grand total is more than 1000 less than or equal to 2000 it is $” and the grand_total to two decimal places; else print on new line “Grand total is greater than 2000 it is $” and the grand_total to two decimal places; just before ending print on new line “Program finished!” then terminate program.
#include<stdio.h>
int main()
{
float NJSALES_TAX = 7.25; //declare and
initialize NJSALES_TAX to 7.25
int total = 1000; //declare and initialize total
to 1000
float grand_total = 0; //declare and initialize
grand_total to 0
printf("\n Enter total : ");
scanf("%d",&total); //read the total
//compute the grand_ttal
grand_total = total + (total *
NJSALES_TAX);
//condition for grand total less than and equal
to 1000
if(grand_total<=1000)
printf("Grand total is less than or equal to
1000 it is $ %0.2f",grand_total);
else //condition for grand_total greater than
1000 and less than or equal to 2000
if(grand_total>1000 &&
grand_total<=2000)
printf("Grand total is more than 1000 less than
or equal to 2000 it is $ %0.2f",grand_total);
else //grand_total greater than 2000
printf("Grand total is greater than 2000 it is
$%0.2f ",grand_total);
//print finished message
printf("\n Program finished!");
}
output