Thread: trouble with if else statements

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    3

    trouble with if else statements

    I"m trying to make my program decide when an input is invalid and use the right cout statement here is the code


    if( s_code = 1022)
    cout <<endl;
    else
    cout << "DENIED: Security Code Mismatch" << endl;

    if( zip_code = 92831)
    cout <<endl;
    else
    cout << "DENIED: Zip Code Mismatch" <<endl;
    if(exp_month <= 12 && exp_year <= 2009 )
    cout << endl;
    else
    cout << "DENIED: Card has Expired" << endl;
    if( avail_b >= 12000)
    cout << " APPROVED"<<endl<<endl<<"Saving new data..."<<endl;
    else
    cout << "DENIED: Insufficient Funds" <<endl;


    // any input the program prints out " APPROVED" i want it to only choose approved if all the statemetn are true

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If I show you
    Code:
    s_code = 1022;
    what does that code do?

    Now, why do you think it does something different just because it's in an if statement?

  3. #3
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    What i am understanding what you want is the below code snippet

    Code:
    if (s_code = 1022)
      cout <<endl;
     else
       cout << "DENIED: Security Code Mismatch" << endl;
    
    if ((zip_code = 92831)                    &&
        (exp_month <= 12 && exp_year <= 2009) &&
        (avail_b >= 12000))
      cout << " APPROVED"<<endl<<endl<<"Saving new data..."<<endl;
     else
       cout << "DENIED: Insufficient Funds" <<endl;
    I didn't understand what you fully but i tried

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    Portugal
    Posts
    25
    that way, you assigned the valu of variable


    if(s_code=1200)
    is the same as

    s_code=1200; if(s_code !=0)cout<<endl;

    if ouy ned the test is

    if(s_code==1200)...
    Last edited by joseCarlos; 10-27-2009 at 02:15 AM.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    3

    reply

    Ok so I figured out how to write the if else statements correct....

    if( s_code==1022)
    cout << "DENIED: Security Code Mismatch" << endl;
    else if( zip_code == zip)
    cout << "DENIED: Zip Code Mismatch" <<endl;
    else if(exp_month <= 12 && exp_year <= 2009 )
    cout << "DENIED: Card has Expired" << endl;
    else if( avail_b >= amount)
    cout << "DENIED: Insufficient Funds" <<endl;
    else
    cout <<" APPROVED"<<endl<<endl<<"Saving new data..."<<endl;

    // now when I enter in an s_code value that is "1022" the program still says "DENIED...." I dont know why eventhoguht i set it to exactly 1022?

    any ideas?

    I"m fairly new to programming so please bare with me

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Because you print DENIED exactly when s_code is 1022.

  7. #7
    Registered User
    Join Date
    Oct 2009
    Posts
    3
    so i want it to only say the "denied" statement when it's false, meaning anything else than 1022

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    So write it. This is not difficult.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    You need to look up the 'not equals to' operator.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help on the homework (if statements)
    By Neotriz in forum C++ Programming
    Replies: 3
    Last Post: 10-14-2009, 12:55 AM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  3. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  4. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  5. Class Function Members and If Statements
    By Team Shadow V2 in forum C++ Programming
    Replies: 10
    Last Post: 02-03-2005, 03:00 PM