Please alittle help-- if/else

This is a discussion on Please alittle help-- if/else within the C++ Programming forums, part of the General Programming Boards category; I've written this program a few different ways but it is not seeing the function in C++6.0. I need to ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    9

    Please alittle help-- if/else

    I've written this program a few different ways but it is not seeing the function in C++6.0.

    I need to have the program identify when I have;
    exterior(1),interior(2);

    If(gallons=1.0||andgallons<=3.0)

    cout>>exterior(1)price||interior(2)price;

    Maybe because I have two different paint values I want to input and only one gallon amount am confusing the program?
    Exterior price is lower then interior. I don't know truthfully this is the first time working with if / else. && ||. If I didn't make my self to clear please let me know. Thank -you.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    > If(gallons=1.0
    Should be ==

    Really, it should be something else - comparing floating point numbers for equality is a bad idea - if you're off by even a tiny amount, it will no longer compare equal.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    154

    Re: Please alittle help-- if/else

    Originally posted by jill
    I've written this program a few different ways but it is not seeing the function in C++6.0.

    I need to have the program identify when I have;
    exterior(1),interior(2);

    If(gallons=1.0||andgallons<=3.0)

    cout>>exterior(1)price||interior(2)price;

    I don't know your whole program, but ...|| andgallons <=... Are you sure andgallons is the variable name? Looks odd, like maybe you're trying to do an || and a &&. But, it's a legal name if that's what you have.
    Should be cout <<, not cout >>. That whole line looks funky. The parantheses look like a function call, and you can't cout an or statement. You can cout exterior by itself or interior by itself, but your if statement should have taken care of the choice. Exterior(1)price doesn't seem right either. if you're cout'ing the result of a function call, the call would be something like cout << exterior(price), or similar.

  4. #4
    Unregistered
    Guest

    Wink

    it might help to put { and }

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    9

    exterior/interior to Brown Drake

    Yes I did catch some of my earlier mistakes today. Ok here goes
    There is a list of prices;
    Exterior Interior
    1 to3 =16.75 16.26
    4 to7 =15.85 15.10

    this goes on a few more steps but thats the general idea;

    if(numberofgallons==1.0<=3.0);
    cout<< Know how do I get this to see exterior price and the interior price.

    I know this is my problem because I have no errors and 4 warnings the warnings are in this section.

    Maybe I should change;
    int// (to)// exterior price, interior price. But am not sure how.

    This is assignment I'd like to work it through but I have spent to many hours on it now I have to get through this thanks.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    154

    Re: exterior/interior to Brown Drake

    Originally posted by jill
    Yes I did catch some of my earlier mistakes today. Ok here goes
    There is a list of prices;
    Exterior Interior
    1 to3 =16.75 16.26
    4 to7 =15.85 15.10

    this goes on a few more steps but thats the general idea;

    if(numberofgallons==1.0<=3.0);
    cout<< Know how do I get this to see exterior price and the interior price.
    This is not right. I think what you want is:
    Code:
    int numGallons;
    double price;
    bool exterior;
    // Insert code to set these variables to something
    if (numGallons <= 3)
       if (exterior)
          price = 16.75;
       else
          price = 16.26;
    else if (numGallons >= 4 && numGallons <= 7)
       if (exterior)
          price = 15.85;
       else
          price = 15.10;
    cout << price << endl;
    There are other ways to do it, but that'll work. Post your own code if you need more help.
    Maybe I should change;
    int// (to)// exterior price, interior price. But am not sure how.
    Not sure what you mean here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issues with using CHAR with IF/ELSE conditions.
    By TheBlackVeil in forum C++ Programming
    Replies: 5
    Last Post: 07-31-2007, 11:58 AM
  2. If/else statement not working
    By zenovy in forum C++ Programming
    Replies: 1
    Last Post: 01-18-2006, 08:26 PM
  3. Alittle help for a beginner please...
    By Xeavor in forum C++ Programming
    Replies: 23
    Last Post: 09-24-2004, 03:10 AM
  4. If/Else Problem
    By Vireyda in forum C Programming
    Replies: 1
    Last Post: 04-13-2004, 03:00 PM
  5. if/else if question
    By Akilla in forum C++ Programming
    Replies: 4
    Last Post: 07-08-2002, 11:06 PM

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