Calculate a discounted price : Constant « Data Type « C / ANSI-C

Home
C / ANSI-C
1.assert.h
2.Console
3.ctype.h
4.Data Structure Algorithm
5.Data Type
6.Development
7.File
8.Function
9.Language Basics
10.Macro Preprocessor
11.Math
12.math.h
13.Memory
14.Pointer
15.setjmp.h
16.signal.h
17.Small Application
18.stdio.h
19.stdlib.h
20.String
21.string.h
22.Structure
23.time.h
24.wctype.h
C Tutorial
C++
C++ Tutorial
Visual C++ .NET
C / ANSI-C » Data Type » ConstantScreenshots 
Calculate a discounted price
Calculate a discounted price

#include <stdio.h>

int main()
{
  const int level1 = 30;
  const int level2 = 50;
  const double discount1 = 0.10;
  const double discount2 = 0.15;
  const double unit_price = 3.50;

  int q1 = 0;
  int q2 = 0;

  int qty_over_level1 = 0;
  int qty_over_level2 = 0;

  printf("Quantity?: ");
  scanf("%d", &q1);
  q2 = q1;

  qty_over_level2 = q1%level2;
  q1 -= qty_over_level2;
  qty_over_level1 = q1%level1;
  q1 -= qty_over_level1;

  printf("\nThe total price for %d is $%.2lf\n", q2,
    unit_price*(q1+(1.0-discount1)*qty_over_level1+(1.0-discount2)*qty_over_level2));
}


           
       
Related examples in the same category
1.Convert inches to yards, feet, and inches
2.Cannot assign value to a constant variable
3.Define a constant value
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.