“Sometimes it is the people no one can imagine anything of who do the things no one can imagine.” ― Sir Alan Turing


ADS

ADS

Tuesday, March 28, 2017

URI - 1038 Snack || Solution in C / C++



Using the following table, write a program that reads a code and the amount of an item. After, print the value to pay. This is a very simple program with the only intention of practice of selection commands.

Input

The input file contains two integer numbers and Yis the product code and is the quantity of this item according to the above table.

Output

The output must be a message "Total: R$ " followed by the total value to be paid, with 2 digits after the decimal point.
Input SampleOutput Sample
3 2Total: R$ 10.00
4 3Total: R$ 6.00
2 3Total: R$ 13.50

SOURCE CODE

#include <stdio.h>

int main() {
  int x, y;
  float price;

  scanf("%d %d", & x, & y);

  if (x == 1) {
    price = (4.00 * y);
  } else if (x == 2) {
    price = (4.50 * y);
  } else if (x == 3) {
    price = (5.00 * y);
  } else if (x == 4) {
    price = (2.00 * y);
  } else if (x == 5) {
    price = (1.50 * y);
  }

  printf("Total: R$ %.2f\n", price);

  return 0;
}

No comments:

Post a Comment