Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C Exercises: New item price and increased price according to the item price table

C Basic Declarations and Expressions: Exercise-104 with Solution

Write a C program that read the item's price and create new item price and increased price of that item according to the item price table.

Item Price Increase Rate
100 - 400.00 14%
400.01 - 800.00 11%
800.01 - 1200.00 9%
1200.01 - 2000.00 6%
Above 2000.00 3%

Sample Solution:

C Code:

#include <stdio.h>

int main () 
{
  float price, increased_price;
  printf("Input the item price:");
  scanf("%f", &price);

  if (price >= 100 && price <= 400){

    increased_price = price*0.14;
    price = price + increased_price;
    printf("New Item price: %.2f\n", price);
    printf("Increased price: %.2f\n", increased_price);
    printf("Increase Percentage: 14%%\n");

  }
  else{

      if (price > 400 && price <= 800){

        increased_price = price*0.11;
        price = price + increased_price;
        printf("New Item price: %.2f\n", price);
        printf("Increased price: %.2f\n", increased_price);
        printf("Increase Percentage: 11%%\n");


        }
        else{

          if (price > 800 && price <= 1200){

            increased_price = price*0.09;
            price = price + increased_price;
            printf("New Item price: %.2f\n", price);
            printf("Increased price: %.2f\n", increased_price);
            printf("Increase Percentage: 9%%\n");

          }
          else{

              if (price > 1200 && price <= 2000){
              increased_price = price*0.06;
              price = price + increased_price;
              printf("New Item price: %.2f\n", price);
              printf("Increased price: %.2f\n", increased_price);
              printf("Increase Percentage: 6%%\n");
            }
            else{

              increased_price = price*0.03;
              price = price + increased_price;
              printf("New Item price: %.2f\n", price);
              printf("Increased price: %.2f\n", increased_price);
              printf("Increase Percentage: 3%%\n");

            }
          }
        }
      }
}

Sample Output:

Input the item price:525
New Item price: 582.75
Increased price: 57.75
Increase Percentage: 11%

Flowchart:

C Programming Flowchart: New item price and increased price according to the item price table.

C programming Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C program that takes two integers and test whether they are multiplies are not.
Next: Write a C program that accepts seven floating point numbers and count the number of positive and negative numbers. Also print the average of all positive and negative values with two digit after the decimal number.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



C Programming: Tips of the Day

Static variable inside of a function in C

The scope of variable is where the variable name can be seen. Here, x is visible only inside function foo().

The lifetime of a variable is the period over which it exists. If x were defined without the keyword static, the lifetime would be from the entry into foo() to the return from foo(); so it would be re-initialized to 5 on every call.

The keyword static acts to extend the lifetime of a variable to the lifetime of the programme; e.g. initialization occurs once and once only and then the variable retains its value - whatever it has come to be - over all future calls to foo().

Ref : https://bit.ly/3fOq7XP