Thread: iff statement

  1. #1
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608

    iff statement

    the code is
    // Hex Code Finder
    // Created by Daniel Strong
    // Special thanks to "cecildasquid" and "Gamer Tazer"
    // Feel free to edit this and redistribute this. but you Must leave the above lines there! exactly how they are!
    #include <iostream>
    #include <string>
    #include <stdlib.h>
    #include <windows.h>
    using namespace std;

    int main()
    {
    string input,output;
    //Pastels -word to hex
    char snow[] = "#fffafa";
    char ghostwhite[] = "#f8f8ff";
    char whitesmoke[] = "#f5f5f5";
    char grainsboro[] = "#dcdcdc";

    //Pastels - hex to word
    char fffafa[] = "snow";
    char f8f8ff[] = "ghost white";
    char f5f5f5[] = "white smoke";
    char dcdcdc[] = "grainsboro";



    cout << "Type in a Color to reveal its Hexcode." << endl ;
    cout << " -or- Type in a Hexcode to reveal its Color." << endl ;
    cout << " -or- Type in all to view all colors indexed." << endl ;
    cout << endl ;
    cout << " WARNING: when you type in a color make sure it is all" << endl ;
    cout << " lowercase and has no spaces if the color has a space in it" << endl ;
    cout << " just combine it. i.e. - 2 words is 2words" << endl ;
    cout << endl ;
    cout << " WARNING: make sure when you type in a hexcode that it" << endl ;
    cout << " does not have the # symbol in it i.e. - #ffffff is ffffff" << endl ;
    cin >> input;

    if(input == "snow")
    output = snow;
    else if(input == "ghostwhite")
    output = ghostwhite;
    else if(input == "whitesmoke")
    output = whitesmoke;
    else if(input == "grainsboro")
    output = grainsboro;


    cout << "The Hexcode for the color " << input << " is " << output << endl ;
    Sleep(5000);


    else if(input == "fffafa")
    output = fffafa;
    else if(input == "f8f8ff")
    output = f8f8ff;
    else if(input == "f5f5f5")
    output = f5f5f5;
    else if(input == "dcdcdc")
    output = dcdcdc;


    cout << "The color of the Hexcode #" << input << " is " << output << endl ;
    Sleep(5000);

    cin.get();
    return 0;
    }
    when i compile it and i input a hex code varible. after all the if statements at the cout its trys to do the first cout but has no output, then it goes thru the scond list of else ifs and finds an output os it makes my complete sentence. how can i make it so it wont display the firts cout message after the first set of ifs. when i put in a varible that corosponds with the second cout. did you get what im saying?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    Well in....
    Code:
    if(input == "snow") 
    output = snow; 
    else if(input == "ghostwhite") 
    output = ghostwhite; 
    else if(input == "whitesmoke") 
    output = whitesmoke; 
    else if(input == "grainsboro") 
    output = grainsboro; 
    
    
    cout << "The Hexcode for the color " << input << " is " << output << endl ; 
    Sleep(5000); 
    
    
    else if(input == "fffafa") 
    output = fffafa; 
    else if(input == "f8f8ff") 
    output = f8f8ff; 
    else if(input == "f5f5f5") 
    output = f5f5f5; 
    else if(input == "dcdcdc") 
    output = dcdcdc;
    Your first "ifs" are OK, but your second set has no initializing "if"... you go right into "else if"....

    try changing
    Code:
    else if(input == "fffafa")
    to
    Code:
    if(input == "fffafa")
    and see if that's what you want... as I don't quite know what you are trying to ask

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    Wait no... now I see what you're probably saying.... try this....
    PHP Code:
    if(input == "snow") {
    output snow;
    cout << "The Hexcode for the color " << input << " is " << output << endl 
    Sleep(5000);
    }
    else if(
    input == "ghostwhite") {
    output ghostwhite
    cout << "The Hexcode for the color " << input << " is " << output << endl 
    Sleep(5000); 
    }
    else if(
    input == "whitesmoke") {
    output whitesmoke
    cout << "The Hexcode for the color " << input << " is " << output << endl 
    Sleep(5000); 
    }
    else if(
    input == "grainsboro") {
    output grainsboro
    cout << "The Hexcode for the color " << input << " is " << output << endl 
    Sleep(5000); 

    and so on...........


    (me likes these PHP tags!)
    Last edited by d00b; 06-15-2002 at 07:54 PM.

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    though that is a bit obtuse... however I suppose it's ok to do in this little program
    Last edited by d00b; 06-15-2002 at 07:53 PM.

  5. #5
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    doob knows wut im trying to do, but i dont want to put that under each if statement. whats that thing about switches, wut r they and wut do they do (im newb to c++) u will hae all standard hex codes in this, theres ALOT. this is nothing close to bening done, well it is, but i still havta add a bunch more hex codes
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

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, 07:18 AM
  4. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM