If statement....

This is a discussion on If statement.... within the C++ Programming forums, part of the General Programming Boards category; hey all, I am having trouble with a program I am writing. Please note that I am a beginner programmer, ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    2

    If statement....

    hey all, I am having trouble with a program I am writing. Please note that I am a beginner programmer, who doesn't know much more than the basics. I used Dev C++ in a programming class I took and decided to stick with it. I have been trying to figure out how to use an If statement to run a couple equations on one variable, if that variable (an integer) is between 2 numbers, in this case between 64 and 1024. The line I am trying to figure out is noted by: (need proper If statement here)

    Code:
    if (num <= 64)
    {
    num2 = (num * 3);
    num3 = (num * 6);
    }
    if (num >= 1024)
    {
    num2 = (num * 1.25);
    num3 = (num * 1.5);
    }
    (need proper If statement here)
    {
    num2 = (num * 1.5);
    num3 = (num * 2.0);
    }
    I propably should have figured this out myself but I have tried everything I can think of. I hope someone here can help me.

    Thanks

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Code:
    if (num <= 64)
    {
         num2 = (num * 3);
         num3 = (num * 6);
    }
    
    else if (num >= 1024)
    {
         num2 = (num * 1.25);
         num3 = (num * 1.5);
    }
    
    else
    {
         num2 = (num * 1.5);
         num3 = (num * 2.0);
    }
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    Code:
    if (condition_1)
    {
        // condition_1 true
    }
    else if (condition_2)
    {
        // condition_1 false, condition_2 true
    }
    else
    {
        // both condition_1 and condition_2 false
    }
    gg

  4. #4
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    ... gah

    Edit: didnt read it right
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    2
    thanks to all of you for your quick replies.....

    The Brain's solution worked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 02:57 AM
  3. If Else statement problem
    By doofusboy in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 06:18 AM
  4. string & if statement
    By Curacao in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 09:56 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 03:49 PM

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