Thread: Question: Illegal Operand Types

  1. #1
    Registered User
    Join Date
    Jan 2014
    Posts
    8

    Question Question: Illegal Operand Types

    Hi Everyone! First of all, please excuse the super simple for dummies question. I'm a total newbie to programming and i'm taking a C class online so it's difficult to get feedback and answers to questions.

    In the below code, can someone please explain why I get an error for 'Left operand is type float / right operand is type const float'? I have spent hours trying to figure this out to no avail! And yes, this is a homework question, but i'm not looking for the complete answer, just help with this one error. Thanks in advance!

    #include <stdio.h>
    const float TAXRATE = 0.056;
    int main(void)
    {
    float price;
    int dollar, cent;


    printf("Please enter the price of your item.\n");
    scanf("%f", &price);


    dollar = price * TAXRATE
    cent = price % TAXRATE;


    printf("Item price $%2f with sales tax is %d dollars and %d cents.", price, dollar, cent);

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    % is remainder after division, but it requires integers (the assumption is, if you're dividing floating-point values, that you want something like 3.85 rather than 3 remainder 6).

  3. #3
    Registered User
    Join Date
    Jan 2014
    Posts
    8
    Oh, jeez. I knew it would be something simple! Looks like I need to rework my approach to the answer all together since the remainder function won't work. Thank you so much!

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by barnbrat View Post
    Oh, jeez. I knew it would be something simple! Looks like I need to rework my approach to the answer all together since the remainder function won't work. Thank you so much!
    You'd be doing that anyway, since (1) dividing by the tax rate isn't going to give you cents in the first place, and (2) you need to come up with a way to turn .4967423 into neither 49 cents nor 49.67423 cents nor 4967423 cents.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. string::operand+ usage problem (with WIN32 data types)
    By flashbaz-pi in forum C++ Programming
    Replies: 17
    Last Post: 11-02-2008, 02:41 PM
  2. Illegal Operand
    By Muphin in forum C++ Programming
    Replies: 5
    Last Post: 09-06-2005, 06:49 AM
  3. illegal operand with & operator
    By Mr_Jack in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2004, 08:26 AM
  4. illegal operand
    By monkey_C in forum C Programming
    Replies: 8
    Last Post: 09-12-2002, 05:53 PM