That Constant Double to Float newbie thing

This is a discussion on That Constant Double to Float newbie thing within the C Programming forums, part of the General Programming Boards category; Hi, newbie here. I am reading my first C book and I am attempting to compile the code so I ...

  1. #1
    Registered User Bassglider's Avatar
    Join Date
    Nov 2007
    Posts
    32

    That Constant Double to Float newbie thing

    Hi, newbie here. I am reading my first C book and I am attempting to compile the code so I can write it as I practice. I googled this error and it told me to put an " f " after %.07 sales tax which gives me a whole new set of errors. If I copied the code straight out of the book why am I having problems? Also I was wondering if the tabbing is correct in this code so I know I am doing it right.

    Thanks

    Code:
    /* Computes net tire sales */
    #include <stdio.h>
    main()
    {
    	int numTires;
    	float tirePrice, beforeTax, netSale;
    	float taxRate = .07; /* Sales Tax */
    	/* Ask user for values */
    	printf("how many tires bought? ");
    	scanf(" %d", &numTires);
    	printf("How much is each tire? ");
    	scanf(" %f", &tirePrice);
    	/* Computer the Sale */
    	beforeTax = tirePrice * numTires;
    	netSale = beforeTax + (beforeTax * taxRate);
    	printf("Your total sale is %.2f\n", netSale);
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    float taxRate = .07f; /* Sales Tax */

  3. #3
    Registered User Bassglider's Avatar
    Join Date
    Nov 2007
    Posts
    32
    Thanks, for some reason the book doesn't write it like that? Whats the deal! It's Sams!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 08:38 PM
  2. Opengl walking leg animation
    By Bobby230 in forum C Programming
    Replies: 3
    Last Post: 03-05-2006, 02:41 PM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM
  4. Im stuck....
    By dAzed in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2004, 04:50 PM
  5. Display list not displaying?
    By psychopath in forum Game Programming
    Replies: 5
    Last Post: 09-19-2004, 06:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21