fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int number;
  5. float price, discount, total;
  6.  
  7. printf("Are you number <1. Yes 2. No>:");
  8. scanf("%d", &number);
  9.  
  10. printf("Enter the purchase price :");
  11. scanf("%f", &price);
  12.  
  13. if ((number == 1) && (price >= 2000)) {
  14. discount = price * 0.1;
  15. total = price - discount;
  16. } else if ((number == 1) && (price < 2000)) {
  17. discount = price * 0.07;
  18. total = price - discount;
  19. } else if ((number == 2) && (price >= 1000)) {
  20. discount = price * 0.05;
  21. total = price - discount;
  22. } else {
  23. discount = 0;
  24. total = price - discount;
  25. }
  26.  
  27. printf("**\n");
  28. printf("The purchase price = %.2f\n", price);
  29. printf("Discount = %.2f\n", discount);
  30. printf("Price after discount = %.2f\n", total);
  31.  
  32. }
Success #stdin #stdout 0.02s 25532KB
stdin
Standard input is empty
stdout
#include <stdio.h>

int main() {
    int number;
    float price, discount, total;

    printf("Are you number <1. Yes 2. No>:");
    scanf("%d", &number);

    printf("Enter the purchase price :");
    scanf("%f", &price);

    if ((number == 1) && (price >= 2000)) {
        discount = price * 0.1;
        total = price - discount;
    } else if ((number == 1) && (price < 2000)) {
        discount = price * 0.07;
        total = price - discount;
    } else if ((number == 2) && (price >= 1000)) {
        discount = price * 0.05;
        total = price - discount;
    } else {
        discount = 0; 
        total = price - discount;
    }

    printf("**\n");
    printf("The purchase price = %.2f\n", price);
    printf("Discount = %.2f\n", discount);
    printf("Price after discount = %.2f\n", total);

}