Question

In: Computer Science

Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant...

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.

Solutions

Expert Solution

#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


Related Solutions

For each of the following write the line(s) of code that: Declares and initializes (creates) an...
For each of the following write the line(s) of code that: Declares and initializes (creates) an ArrayList that holds String objects Adds to your ArrayList the words "Too" and "Fun" Verifies that your ArrayList now contains 2 elements Sets the second String in the ArrayList to "No" Verifies that your ArrayList still contains exactly 2 elements Prints the contents of the ArrayList to the screen in the following format: <element>, <element>, . . . , <element>
In C programming: Write a program that initializes an array-of-double and then copies the contents of...
In C programming: Write a program that initializes an array-of-double and then copies the contents of the array into another arrays. To make the copy, use a function with array notation. This function takes two arguments the name of the target array and the number of elements to be copied. That is, the function calls would look like this, given the following declarations: double source[5] ={1.1, 2.2, 3.3., 4.4, 5.5}; double target1[5]; double target2[5]; copyarr(source, target1, 5);
1. a. In C++, Write a program that creates an array of 20 integers and initializes...
1. a. In C++, Write a program that creates an array of 20 integers and initializes it with the even values starting from 200. i.e. 200, 202, 204…. b. Write the elements of the array to the file even.txt, each element on a separate line. Try to use a single for loop for initializing the array and writing to file. You will need a separate counter for initializing the array. 2. a. Write another program that opens the file even.txt...
Write Java program Lab43.java which declares and initializes numeric array of 5 elements (int num[5]) and...
Write Java program Lab43.java which declares and initializes numeric array of 5 elements (int num[5]) and produces as output the sum of integers in an array, the largest and the smallest element in an array. Your program should contain the following methods: public static int sum(int[]) public static int findLargest(int[]) public static int findSmallest(int[])
In C, write a program that initializes a 3D array (the exact size doesn't matter) that...
In C, write a program that initializes a 3D array (the exact size doesn't matter) that contain what ever arbitrary integers and print out the array including the elements and use different functions so that the main only contains variables and function calls.
2. Write a program in C++ that: a) Declares a 1D array A with 30 elements...
2. Write a program in C++ that: a) Declares a 1D array A with 30 elements b) Inputs an integer n from 1-30 from the keyboard. If n < 1 set n = 1. If n > 30 set n = 30. the program should keep asking the user the input n one by one, followed by printing of the value of n (n=n if bigger than 1 and smaller than 30, 1 if smaller than 1 and 30 if...
C Code Please! Declares a constant variable N and sets it to 42. * Declares an...
C Code Please! Declares a constant variable N and sets it to 42. * Declares an array of integers, with N elements, called fibonacci. * Declares an array of double floating-point numbers, with N-1 elements, called ratio. * Fills the fibonacci array with the numbers in the Fibonacci sequence (Wikipedia is your friend if you don't know what this sequence is about but you want to know).    Into the i-th element of the fibonacci array, you need to put...
Write a small C program connect.c that: 1. Initializes an array id of N elements with...
Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and changing all the entries with the same name as p to have the same...
Write a small C program connect.c that: 1. Initializes an array id of N elements with...
Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and changing all the entries with the same name as p to have the same...
Write a program in C that declares the following array: int. array[] = { 1, 2,...
Write a program in C that declares the following array: int. array[] = { 1, 2, 4, 8, 16, 32 } Then write some code that accepts a number between 0 and 5 from the user and stores it in a variable called "index". Write some code that retrieves the item specified by the index, like this: int item = array[index]; Then write code that outputs the corresponding array entry based on the number the user entered. Example output: The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT