Help! beginner level question

This is a discussion on Help! beginner level question within the C Programming forums, part of the General Programming Boards category; I am making a program that if a fee exceeds a certain amount it, it will default to the max ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    3

    Help! beginner level question

    I am making a program that if a fee exceeds a certain amount it, it will default to the max fee. Not sure what I'm doing wrong...what should I do to correct it?


    Code:
    {
          if (totalfee > maxfeeTruck && typeofVehicle == 'T')
               totalfee=maxfeeTruck;
          else if (totalfee> maxfeeCar&& typeofVehicle == 'C')
               totalfee=maxfeeCar;
          else if( totalfee > maxfeeBus && typeofVehicle=='B')
               totalfee=maxfeeBus;
      }
       return;
        }
    Last edited by seking10788; 07-06-2011 at 08:53 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You should properly parenthesize (notice how two of the && lines are right and one is wrong).

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    3
    I tried that and it didn't work.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    What did you try?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    Just a tip-- I would be a little careful using the name typeof in a C program. It has a special meaning and adding it to a variable name can be a little misleading. I would possibly rename them vehicleType etc.

  6. #6
    Registered User
    Join Date
    Jul 2011
    Posts
    3
    I edited the code after I realized I had parenthesis in the wrong place. I keep getting an error about comparison between pointer and int

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    2,372
    Quote Originally Posted by seking10788 View Post
    I edited the code after I realized I had parenthesis in the wrong place. I keep getting an error about comparison between pointer and int
    And you declared typeofVehicle as what?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 20
    Last Post: 09-29-2010, 11:56 AM
  2. Can someone help me with this beginner-level program?
    By matthayzon89 in forum C Programming
    Replies: 5
    Last Post: 05-09-2010, 11:00 AM
  3. A beginner level problem with char datatype
    By stiltz in forum C Programming
    Replies: 3
    Last Post: 03-25-2010, 11:08 AM

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