tags:

views:

178

answers:

2

My teacher gave me an assignment:

Write a program to input retail price of a product. If a 6.5% discount is given to a customer, then find and print the selling price.

Additional Details: I'm new to programming. I haven't learned any functions except printf() and Scanf().

Please write the program using only these functions. I have done it, thanks for helping.

#include <stdio.h>
main()
{
 int retail_price, selling_price, discount;
 printf("Enter Retail Price of the product:-");
 scanf("%d", &retail_price);
 discount=6.5;
 selling_price=retail_price-discount;
 printf("Selling Price of the product is:- %d",selling_price);
 getch();
}
A: 

I guess the sollution is in your textbook. Or ask your schoolmates.

Stefanvds
+6  A: 

Let's try and break this down a little...

What do we need to know first? The retail price. How do we ask the user for it:

//todo: ask for the retail price, and put it in retailPrice

Now we have the retail price. Suppose it is in a variable called retailPrice. How do we get the discounted price? Do some math, and put the result in a new variable:

//todo: calculate the discounted price, and put it in discountedPrice

Now we need to display the discounted price. How can we print a variable to the screen:

//todo: show the discounted price.

Good luck. It gets easier the more you practice.

Lance Fisher
Thanks Lance Fisher for helping me, it's work for me.! thanks again.
Najam Awan
How can that works ?!
Cedric H.
Good to hear it Najam! It really does get easier. I remember the painful days.
Lance Fisher
main() { int retail_price, selling_price, discount; printf("Enter Retail Price of the product:-"); scanf("%d", discount=6.5; selling_price=retail_price-discount; printf("Selling Price of the product is:- %d",selling_price); getch(); }
Najam Awan
@Najam: This will subtract a fixed amount instead of a percentage. Do you know what a percentage is?
Tim Pietzcker
The discount should not be 6.5. It should be 6.5 percent of the retail price. 6.5 percent should be written as .065. In math, almost anytime you see the work of it means multiply. So 6.5 percent of the retail price should be calculated as .065 * retail_price.
Lance Fisher