Results 1 to 7 of 7

Thread: what happened here

  1. #1
    Regular Member MAmuT's Avatar
    Join Date
    Nov 2001
    Location
    Houston, TX
    Posts
    467

    Unhappy what happened here

    sup my girlfriend asked me to ask her ou tby doing a c++ program WHAT A FOOL so i kin dof did one but i recive 2 errors and i cant find them you ppl should know that i am a newbie so............ here is the code

    #include <iostream>
    using namespace std;

    int main()
    {

    char letter = 0;

    cout << endl
    << "Hi Steph, how are you? (cool or bad): ";
    cin >> letter;

    if(letter == 'cool')
    {
    char letter2 = 0;

    cout << endl
    << " Good. What are you going to do this weekend? ( gout or nada ). ";
    cin >> letter2;

    if(letter2 == 'gout')
    {
    cout << endl
    << " If you are going with Ana tell me,so maybe i can catch up you ok?. If not maybe next time. "
    << endl;
    return 0;
    }


    if(letter2 == 'nada')
    {
    cout << endl
    << " Well maybe we can fix somthing and go out you, maybe Ana, someone else you want and ME."
    << " WHAT YOU SAY ? If yes IM me(AIM). If not well maybe next time "
    << endl;
    return 0;
    }

    }

    if(letter == 'bad')
    {
    cout << endl
    << " Well maybe next time, see you later"
    << endl;
    return 0;
    }


    cout << endl << "MADE BY PToN 11/27/2001 10:45 PM." << endl;

    return 0;
    }

  2. #2
    Regular Member
    Join Date
    Aug 1999
    Posts
    341
    letter is of type char, but you are trying to compare it with a char*--kind-of, a single char goes in single quotes, a char* or string goes in double quotes. To compare a char* to a static character string you need to use the strcmp() function from the C library string.h (a.k.a cstring). Also, using if/else if instead instead of the two if's will let you re-use the variable letter--so, letter2 is not needed. Here's the re-write:

    Code:
    #include <iostream>
    #include <cstring>
    using namespace std; 
    
    int main(){
    
      char *letter = '\0';  // Changed to a char * and
                            // initialized to a null string
    
      cout << endl
           << "Hi Steph, how are you? (cool or bad): ";
      cin >> letter;
    
      if(strcmp(letter, "cool") == 0){ // Changed to use strcmp()
    
        cout << endl
             << " Good. What are you going to do this weekend? ( gout or nada ). ";
        cin >> letter;
    
        if(strcmp(letter, "gout") == 0){ // Changed to use strcmp()
    
          cout << endl
               << " If you are going with Ana tell me,so maybe i can catch up you ok?. If not maybe next time. "
               << endl;
          return 0;
    
        } else if(strcmp(letter, "nada") == 0){ // Changed to use strcmp()
          cout << endl
               << " Well maybe we can fix somthing and go out you, maybe Ana, someone else you want and ME."
               << " WHAT YOU SAY ? If yes IM me(AIM). If not well maybe next time "
               << endl;
          return 0;
    
        }
    
      } else if(strcmp(letter, "bad") == 0){ // Changed to use strcmp()
    
        cout << endl
             << " Well maybe next time, see you later"
             << endl;
        return 0;
    
      }
    
    
      cout << endl << "MADE BY PToN 11/27/2001 10:45 PM." << endl;
    
      return 0;
    
    }

  3. #3
    Regular Member MAmuT's Avatar
    Join Date
    Nov 2001
    Location
    Houston, TX
    Posts
    467

    thank you very much

    thanks man you have saved my life

  4. #4
    Regular Member MAmuT's Avatar
    Join Date
    Nov 2001
    Location
    Houston, TX
    Posts
    467

    CRAP AGAIN STU HELP PLZ

    stu look here its what the debugger always tell me even with the old code

    LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
    Debug/salida.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.


    thst with the code you gave me and with the firts one

    thats working on a project for a win32 apliccation and an empty project

    help again dude

  5. #5
    Regular Member
    Join Date
    Aug 1999
    Posts
    341
    More likely than not, you are either using the compiler wrong or the compiler is not configured correctly (or not installed properly). I'm not sure what the problem could be, because I run Linux/Unix almost exclusively and am not to familiar with the windows compilers. I will tell you that I compiled the version in my reply with GCC and it worked fine--no problems whatsoever.

    Perhaps you should tell us which compiler you are using, and maybe someone who knows that compiler in here could help you out.

  6. #6

    check this

    I use the windows and when I compiled that code, I didn't get those errors. Why not just do this

    #include <iostream>
    #include <string>
    using namespace std;

    int main(){

    string letter;

    cout << endl
    << "Hi Steph, how are you? (cool or bad): ";
    cin >> letter;

    if(letter == "cool"){
    cout << endl
    << " Good. What are you going to do this weekend? ( gout or nada ). ";
    cin >> letter;

    if(letter =="gout"){

    cout << endl
    << " If you are going with Ana tell me,so maybe i can catch up you ok?. If not maybe next time. "
    << endl;


    } else if(letter == "nada"){
    cout << endl
    << " Well maybe we can fix somthing and go out you, maybe Ana, someone else you want and ME."
    << " WHAT YOU SAY ? If yes IM me(AIM). If not well maybe next time "
    << endl;
    }

    } else if(letter == "bad"){

    cout << endl
    << " Well maybe next time, see you later"
    << endl;


    }
    return 0;
    }

    This way worked without errors. I would however be interested in knowing what problems this way could have. Stu, you seem to be the expert. Whatcha think, bad efficiency? Wondering? O and I'll have some questions to throw your way stu soon. Lucky you.
    "Good...Bad...I'm the guy with the gun"
    -- Army of Darkness --

    In case I forget, thanks STU!!

  7. #7
    Regular Member MAmuT's Avatar
    Join Date
    Nov 2001
    Location
    Houston, TX
    Posts
    467
    ok i am copilling with the copiller that comes with C++ 6 and i have copilled with that one before but i thin k that now it doesnt work so what copiller would it be good in order to copile

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •