| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
a lil help
Code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(int nNumberofArgs, Char* pzArg[])
{
cout << "Hello\n;";
cout << "Whuts up?";
char whatever[20];
cin << whatever[];
if (whatever == "nothing" || "NOTHING")
{
cout << "kool";
}
if (whatever == "programming" || "PROGRAMING")
{
cout << "me 2";
}
else;
{
cout << "awesome\n";
}
system("PAUSE");
return 0;
}
The first comparasion work but if i type programming it inputs kool instead of me 2 and the else thing won't work and once it inputs kool it ends the program (i know my programing skills are low but im working on them ) |
|
#2
|
|||
|
|||
|
Ok I can spot 3 immediate problems with this code -
1) You can't use the == operator with character arrays since this tries to compare the pointers not the strings that they point to. Have a look at the function strcmp to do this. (Equally be aware you can't just use = either and need to use strcpy instead). 2) if (whatever == "nothing" || "NOTHING") is syntactically correct but doesn't do what you think it does. After each || or && you need to specify a new comparison operator so whatever == "NOTHING" rather than just "NOTHING" but keep in mind point 1. 3) You have a semicolon after your else statement which has no place being there. Hope these points help, c/c++ strings are a pain to learn about so stick with it. -KM- |
|
#3
|
|||
|
|||
|
I spotted one other problem.
"cin <<" should be: "cin >>" Good luck with C++ |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > a lil help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|