| | |
c++ error
![]() |
•
•
Join Date: Feb 2010
Posts: 40
Reputation:
Solved Threads: 0
here is my script:
i get an error :
ISO C++ forbids comparision between pointer and integer
how do i fix this? and what is actually causing this and why is it like that?
also im just starting out in codeing and wanted to know if there was a way i can make it so i can run it in anything besides CMD.
like if i could make it so when someone clicks on it , it opens up in like a window that i choose or something then it has buttons where it has the different types of code i put in there...
any help will be appreciated.
thanks.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cmath> int main() { using namespace std; int who; cout << "how are you today? good, bad, or eh?" << endl; cin >> who; if (who == "good") { cout << "ahh thats pretty cool i guess..." << endl; } if (who == "bad") { cout << "LOL that sucks for you!!!!" << endl; } if (who == "eh") { cout << "EHHHHHHHHHHHHH!!!" << endl; } else { cout << "i dont know what that means? close and retry please..." << endl; } cout << "god im so bored" << endl; cout << endl; system("pause") return 0; }
i get an error :
ISO C++ forbids comparision between pointer and integer
how do i fix this? and what is actually causing this and why is it like that?
also im just starting out in codeing and wanted to know if there was a way i can make it so i can run it in anything besides CMD.
like if i could make it so when someone clicks on it , it opens up in like a window that i choose or something then it has buttons where it has the different types of code i put in there...
any help will be appreciated.
thanks.
Last edited by Nick Evan; Feb 10th, 2010 at 3:37 am. Reason: Added code-tags
0
#2 Feb 6th, 2010
What is the data type of your input variable?
Are you comparing it to a similar type value? No.
If you want to compare to "good" or "bad" or "crappy" or ... you must take your input as a string. If you use C-style (char array based) strings, you must the use one of the comparison functions. If you use the C++ string class, then your comparison method will work.
Master the fundamentals of console applications first, then you can move on to writing windowed programs. Or fire up Visual Basic.
Also, in the future please post your program using the code tags:
[code]
your code goes here
[/code]
Are you comparing it to a similar type value? No.
If you want to compare to "good" or "bad" or "crappy" or ... you must take your input as a string. If you use C-style (char array based) strings, you must the use one of the comparison functions. If you use the C++ string class, then your comparison method will work.
Master the fundamentals of console applications first, then you can move on to writing windowed programs. Or fire up Visual Basic.
Also, in the future please post your program using the code tags:
[code]
your code goes here
[/code]
Last edited by vmanes; Feb 7th, 2010 at 12:01 am.
Don't own a gun but I'm going to join the NRA.
I figure anything that irritates liberals is worth my support.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
I figure anything that irritates liberals is worth my support.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
•
•
Join Date: Feb 2010
Posts: 40
Reputation:
Solved Threads: 0
0
#3 Feb 7th, 2010
•
•
•
•
What is the data type of your input variable?
Are you comparing it to a similar type value? No.
If you want to compare to "good" or "bad" or "crappy" or ... you must take your input as a string. If you use C-style (char array based) strings, you must the use one of the comparison functions. If you use the C++ string class, then your comparison method will work.
Master the fundamentals of console applications first, then you can move on to writing windowed programs. Or fire up Visual Basic.
Also, in the future please post your program using the code tags:
[code]
your code goes here
[/code]
C++ Syntax (Toggle Plain Text)
char array[3]; array[0] = good; array[1] = bad; array[2] = crappy; char who; cout << "whatever" << endl; cin >> who if (who == [0]) { cout << "whatever i want" << endl; } if (who == [1]) { cout << "what i want" << end; } if (who == [2]) { cout << "whatever i want" << endl; } else { cout << "whatever" << endl; }
Last edited by skorm909; Feb 7th, 2010 at 12:08 am.
0
#4 Feb 7th, 2010
If you are taking a class or working from a textbook on your own, I think you need to go back and review the first few chapters.
Or take some time to peruse this tutorial site.
Or take some time to peruse this tutorial site.
Don't own a gun but I'm going to join the NRA.
I figure anything that irritates liberals is worth my support.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
I figure anything that irritates liberals is worth my support.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
•
•
Join Date: Feb 2010
Posts: 40
Reputation:
Solved Threads: 0
0
#5 Feb 7th, 2010
•
•
•
•
If you are taking a class or working from a textbook on your own, I think you need to go back and review the first few chapters.
Or take some time to peruse this tutorial site.
and no im not taking a class, i just came across c++ one day (yesterday) and decided to try it out.
•
•
Join Date: Sep 2009
Posts: 1,803
Reputation:
Solved Threads: 222
0
#6 Feb 7th, 2010
Vmanes is right, but also find a good book or resource online (I know that Schildt's book is available on Microsoft's site for free -- I think you need a login/hotmail to get access to it) or look at the sticky thread at the beginning of this forum.
It's important to follow someone else's framework initially so you can get on the right track. Like any other language, you can pick up a lot in a short period of time but to do anything useful with it you must practice the correct syntax and grammar.
So kudos to you for taking it up only yesterday but be sure to get the fundamentals down early.
It's important to follow someone else's framework initially so you can get on the right track. Like any other language, you can pick up a lot in a short period of time but to do anything useful with it you must practice the correct syntax and grammar.
So kudos to you for taking it up only yesterday but be sure to get the fundamentals down early.
•
•
Join Date: Feb 2010
Posts: 40
Reputation:
Solved Threads: 0
0
#7 Feb 7th, 2010
i already got the
then make a few commands with it but i cant do too much yet lol
like just a second ago following a link from above i made this:
everything works the way i want it to except when it gets to the "whatsup" part and i type in what i set as an "if" function it only goes to my "else" function...
got any ideas?
but other than that do you think thats good for a first day?
im just trying to learn and ive just been messing around alittle after i posted that...
my main problem is i dont know what the difference is from
and
C++ Syntax (Toggle Plain Text)
int whatever
like just a second ago following a link from above i made this:
C++ Syntax (Toggle Plain Text)
#import <iostream> #import <cmath> using namespace std; int main() { char question[] = "please type in your mood: "; char responding[] = "thats alot of fun to be "; char yourname [80]; char hehe [] = "whatever... i think its fun..."; char lol [80]; char hi [] = "whatsup? pick one: nothing, everything, tired, lame"; char rofl [80]; cout << question; cin >> yourname; cout << responding << yourname << " isnt it?" << endl; cin >> lol; cout << hehe << endl; cout << hi << endl; cin >> rofl; if (rofl == "nothing") { cout << "you better get to do something soon then!" << endl; } if (rofl == "everything") { cout << "you better start doing less stuff then..." << endl; } if (rofl == "tired") { cout << "THEN GET SOME SLEEP!" << endl; } if (rofl == "lame") { cout << "this isnt lame this is fun!"<< endl; } else { cout << "restart and type in a real answer..." << endl; } system("pause"); return 0; }
everything works the way i want it to except when it gets to the "whatsup" part and i type in what i set as an "if" function it only goes to my "else" function...
got any ideas?
but other than that do you think thats good for a first day?
im just trying to learn and ive just been messing around alittle after i posted that...
my main problem is i dont know what the difference is from
C++ Syntax (Toggle Plain Text)
int name
C++ Syntax (Toggle Plain Text)
char name
Last edited by skorm909; Feb 7th, 2010 at 2:29 am.
0
#8 Feb 7th, 2010
Not bad for a first day. One thing you need to learn right away is this, though.
Last edited by WaltP; Feb 7th, 2010 at 3:55 am.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Feb 2010
Posts: 40
Reputation:
Solved Threads: 0
0
#9 Feb 7th, 2010
ya i got most of the add spaces between each bit of code already but just found out about the
thanks every bit helps =)
C++ Syntax (Toggle Plain Text)
if (blank == "whatever") cout << "whatever" << endl;
•
•
Join Date: Sep 2009
Posts: 1,803
Reputation:
Solved Threads: 222
0
#10 Feb 7th, 2010
Chars are actually 1 byte integers! Check out this table. If you have a char 'a' (note the single quotes for chars) it's actually stored as (the bits representing) 97. There's lots of great resources on ASCII, Unicode (encompasses a lot more characters, including international alphabets), etc. out there on the net. Just for you own personal interest, no need to learn everything about them before you start.
![]() |
Similar Threads
- GTK Hangs & An Index Error (C#)
- Php email error (PHP)
- When I boot computer Error Appear. (Windows Vista and Windows 7)
- Error with a linked function (C++)
- How to Fix "Error loading Operating System" (Windows NT / 2000 / XP)
- XML to XML via XSL Transform Error... (XML, XSLT and XPATH)
- javac error message (Java)
Other Threads in the C++ Forum
- Previous Thread: Using a full color menu in a console app
- Next Thread: error C2447
Views: 1528 | Replies: 52
| Thread Tools | Search this Thread |
Tag cloud for c++
.dll algorithm array arrays assignment basic beginner binary bitmap buttons c++ c++borland calculator char char* class client code compile compiler console constructor convert cout delete desktop development dos embedded encryption error file filestream fstream function functions game graph gui homework input int java job jobs library link linker linux loop math matrix microsoft multidimensional newbie null numbers objects optimization output performance pointer pointers prime problem problems program programing programming project projects python qt read recursion recursive rpg space sql stream string strings struct studio switch system template templates text toolbar tree url vector visual win32 window windows winsock world xml







