if else

This is a discussion on if else within the C++ Programming forums, part of the General Programming Boards category; im trying to write a program that contains if , else. when i compile it there are no errors, but ...

  1. #1
    Registered User
    Join Date
    Sep 2006

    Question if else

    im trying to write a program that contains if , else. when i compile it there are no errors, but when you run it it will only give you the result of what is in the IF statement. Can anyone please help me figure out what im doing wrong? I copied and pasted what i have so far ...

    #include  <iostream>
    #include  <iomanip>
    using namespace std;
    const double Connect_Fee = 1.99;
    const double one_to_three_min = 2.00;
    const double additional_min = 0.45;
     int main ()
        int numOfMinUsed;
        double amountDue;
        cout << endl;
        cout << fixed << showpoint;
        cout << setprecision(2);
        cout << "Enter the number of minutes the call lasted from "
             << "New York to New Delhi." << endl;
        cin >> numOfMinUsed;
        cout << endl;    
        if (one_to_three_min<= 3)
           amountDue = Connect_Fee
           amountDue = Connect_Fee
                         + one_to_three_min
                         + (numOfMinUsed -3) * 
                         + additional_min;
        cout << "Amount due: $"
             << amountDue << endl;
        return 0;
    Last edited by moe47; 09-15-2006 at 01:19 PM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Use code tags.

    Then think about the if condition.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Please place your code in [code] and [/code] forum bbcode tags.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > if (one_to_three_min<= 3)
    Because you declared this as a const, you basically said
    if (2.0<= 3)
    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.

  5. #5
    Registered User
    Join Date
    Sep 2006
    thank you, I didnt even catch that. I have now fixed the problem.

Popular pages Recent additions subscribe to a feed

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