c++ error

Reply

Join Date: Feb 2010
Posts: 40
Reputation: skorm909 is an unknown quantity at this point 
Solved Threads: 0
skorm909 skorm909 is offline Offline
Light Poster

c++ error

 
0
  #1
Feb 6th, 2010
here is my script:

  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. int main()
  5. {
  6. using namespace std;
  7.  
  8. int who;
  9.  
  10.  
  11.  
  12. cout << "how are you today? good, bad, or eh?" << endl;
  13. cin >> who;
  14. if (who == "good")
  15. {
  16. cout << "ahh thats pretty cool i guess..." << endl;
  17. }
  18. if (who == "bad")
  19. {
  20. cout << "LOL that sucks for you!!!!" << endl;
  21. }
  22. if (who == "eh")
  23. {
  24. cout << "EHHHHHHHHHHHHH!!!" << endl;
  25. }
  26. else
  27. {
  28. cout << "i dont know what that means? close and retry please..." << endl;
  29. }
  30. cout << "god im so bored" << endl;
  31. cout << endl;
  32. system("pause")
  33. return 0;
  34.  
  35. }


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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,820
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 213
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso
 
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]
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2010
Posts: 40
Reputation: skorm909 is an unknown quantity at this point 
Solved Threads: 0
skorm909 skorm909 is offline Offline
Light Poster
 
0
  #3
Feb 7th, 2010
Originally Posted by vmanes View Post
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]
so if i do like...
  1. char array[3];
  2. array[0] = good;
  3. array[1] = bad;
  4. array[2] = crappy;
  5. char who;
  6.  
  7. cout << "whatever" << endl;
  8. cin >> who
  9.  
  10. if (who == [0])
  11. {
  12. cout << "whatever i want" << endl;
  13. }
  14.  
  15.  
  16. if (who == [1])
  17. {
  18. cout << "what i want" << end;
  19. }
  20.  
  21.  
  22. if (who == [2])
  23. {
  24. cout << "whatever i want" << endl;
  25. }
  26. else
  27. {
  28. cout << "whatever" << endl;
  29. }
Last edited by skorm909; Feb 7th, 2010 at 12:08 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,820
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 213
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso
 
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.
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2010
Posts: 40
Reputation: skorm909 is an unknown quantity at this point 
Solved Threads: 0
skorm909 skorm909 is offline Offline
Light Poster
 
0
  #5
Feb 7th, 2010
Originally Posted by vmanes View Post
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.
well the thing is i know things here and there from that site from looking at things on youtube so i just wouldnt know where to start..

and no im not taking a class, i just came across c++ one day (yesterday) and decided to try it out.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 1,803
Reputation: jonsca is a glorious beacon of light jonsca is a glorious beacon of light jonsca is a glorious beacon of light jonsca is a glorious beacon of light jonsca is a glorious beacon of light 
Solved Threads: 222
Sponsor
jonsca jonsca is offline Offline
Posting Virtuoso
 
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2010
Posts: 40
Reputation: skorm909 is an unknown quantity at this point 
Solved Threads: 0
skorm909 skorm909 is offline Offline
Light Poster
 
0
  #7
Feb 7th, 2010
i already got the
  1. int whatever
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:

  1. #import <iostream>
  2. #import <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9. char question[] = "please type in your mood: ";
  10. char responding[] = "thats alot of fun to be ";
  11. char yourname [80];
  12. char hehe [] = "whatever... i think its fun...";
  13. char lol [80];
  14. char hi [] = "whatsup? pick one: nothing, everything, tired, lame";
  15. char rofl [80];
  16. cout << question;
  17. cin >> yourname;
  18. cout << responding << yourname << " isnt it?" << endl;
  19. cin >> lol;
  20. cout << hehe << endl;
  21. cout << hi << endl;
  22. cin >> rofl;
  23. if (rofl == "nothing")
  24. {
  25. cout << "you better get to do something soon then!" << endl;
  26. }
  27. if (rofl == "everything")
  28. {
  29. cout << "you better start doing less stuff then..." << endl;
  30. }
  31. if (rofl == "tired")
  32. {
  33. cout << "THEN GET SOME SLEEP!" << endl;
  34. }
  35. if (rofl == "lame")
  36. {
  37. cout << "this isnt lame this is fun!"<< endl;
  38. }
  39. else
  40. {
  41. cout << "restart and type in a real answer..." << endl;
  42. }
  43.  
  44. system("pause");
  45. return 0;
  46. }

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
  1. int name
and
  1. char name
Last edited by skorm909; Feb 7th, 2010 at 2:29 am.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 4,261
Reputation: WaltP has a brilliant future WaltP has a brilliant future WaltP has a brilliant future WaltP has a brilliant future WaltP has a brilliant future WaltP has a brilliant future WaltP has a brilliant future WaltP has a brilliant future WaltP has a brilliant future WaltP has a brilliant future WaltP has a brilliant future 
Solved Threads: 404
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Industrious Poster
 
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2010
Posts: 40
Reputation: skorm909 is an unknown quantity at this point 
Solved Threads: 0
skorm909 skorm909 is offline Offline
Light Poster
 
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
  1. if (blank == "whatever") cout << "whatever" << endl;
thanks every bit helps =)
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 1,803
Reputation: jonsca is a glorious beacon of light jonsca is a glorious beacon of light jonsca is a glorious beacon of light jonsca is a glorious beacon of light jonsca is a glorious beacon of light 
Solved Threads: 222
Sponsor
jonsca jonsca is offline Offline
Posting Virtuoso
 
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.
Reply With Quote Quick reply to this message  
Reply

Tags
c++

Message:



Similar Threads
Other Threads in the C++ Forum


Views: 1528 | Replies: 52
Thread Tools Search this Thread



Tag cloud for c++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC