[URI Online Judge] – 1038 – Snack

Using the following table, write a program that reads a code and a 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.


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


The output must be a message “Total: R$ ” followed by the total value to be paid, with 2 digits after the decimal point.

Sample Input Sample Output
3 2 Total: R$ 10.00
4 3 Total: R$ 6.00
2 3 Total: R$ 13.50


#include <cstdio>
int main(){
 int n, q;
 scanf("%d %d", &n, &q);
 if (n == 1)
 printf("Total: R$ %.2f\n", 4.00 * q);
 else if (n == 2)
 printf("Total: R$ %.2f\n", 4.50 * q);
 else if (n == 3)
 printf("Total: R$ %.2f\n", 5.00 * q);
 else if (n == 4)
 printf("Total: R$ %.2f\n", 2.00 * q);
 printf("Total: R$ %.2f\n", 1.50 * q);
 return 0;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s