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

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
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
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
w_w__w_.__j_a_va__2s___.___com___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.