PDA

View Full Version : what happened here



MAmuT
11-29-01, 10:21 AM
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;
}

Stu
11-29-01, 05:48 PM
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:




#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;

}

MAmuT
11-29-01, 10:37 PM
thanks man you have saved my life

MAmuT
11-29-01, 10:42 PM
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

Stu
11-30-01, 09:45 AM
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.

Orphious
11-30-01, 11:41 AM
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? :D O and I'll have some questions to throw your way stu soon. Lucky you.

MAmuT
11-30-01, 05:41 PM
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