Thread: A dumb loop problem

  1. #1
    Registered User
    Join Date
    Apr 2014

    A dumb loop problem

    Hi everyone;

    My homework is this.A Bookseller makes special discount for multiple orders of a book as follows: AMOUNT and DISCOUNT as follows.5-9 5% 10-14 10% 15-19 15% 20+ 20% Write a C main function to read the amount of order from the standardinput and compute and print the total price of the given order after thediscount. Assume that unit price of a book is 10.00$

    my problem is that.When i start with this

         #include <stdlib.h>
         int main(void)
             int number;
             float TotalPrice;
             printf("enter a number:");
             if(number<=5) {
                           printf("Your Total Price is :%d", TotalPrice);
                   return 0;

    i get 0 if i enter a number between 0 and 4(0 and 4 included)

    i dont know where im doing a mistake.
    i also want to know if i can handle this buy just if statements.
    or how can i do it by while and for loops ?

    Thank you.

  2. #2
    Registered User
    Join Date
    Aug 2005
    printf("Your Total Price is :%d", TotalPrice);
    You're using the wrong fotmat to print a float %d is for integers
    And then you should calculate TotalPrice before printing it's value.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dumb this down
    By les2012 in forum Tech Board
    Replies: 5
    Last Post: 12-09-2012, 09:13 AM
  2. Dumb editbox problem ...
    By xlines in forum Windows Programming
    Replies: 3
    Last Post: 12-01-2007, 12:31 PM
  3. Dumb Problem
    By Maragato in forum C Programming
    Replies: 2
    Last Post: 07-22-2004, 02:18 PM
  4. another dumb question - loop not working?
    By Captain Penguin in forum C++ Programming
    Replies: 8
    Last Post: 10-06-2002, 10:15 PM
  5. Im new and dumb :)
    By Prodigy in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2002, 11:27 AM