473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Skips through all "Couts" in bool

134 100+
C++:
The problem is when I run 'bool CheckLevelUp()'.
As you can see, i set 'PlayersExp' to 0.
When i run 'bool CheckLevelUp()' it says...

"You Are Level One
You Are (Now) Level Two
You Are (Now) Level Three"

and it should just say

"You are Level One"

Im guessing it has to do with how i put "PlayersExp=0-4);" and "PlayersExp=5-10);"...
Anybody know the problem- or even better, a fix?
thanks.

Expand|Select|Wrap|Line Numbers
  1. #include "Library.h"
  2. int PlayersExp = 0;
  3. int PlayersLevel=1;
  4.  
  5.  
  6. bool CheckLevelUp()
  7. {
  8.      if (PlayersExp=0-4);
  9.      {
  10.        cout<<"You Are Level 1\n";  
  11.  
  12.      }    
  13.      if (PlayersExp=5-9);
  14.      {
  15.        cout<<"You are (Now) Level 2\n";
  16.        PlayersLevel=2;
  17.      }
  18.      if (PlayersExp=10-19);
  19.      {
  20.        cout<<"You Are (Now) Level 3\n";
  21.        PlayersLevel=3;
  22.      }
  23. }
  24.  
Apr 29 '07 #1
4 1222
ilikepython
844 Expert 512MB
C++:
The problem is when I run 'bool CheckLevelUp()'.
As you can see, i set 'PlayersExp' to 0.
When i run 'bool CheckLevelUp()' it says...

"You Are Level One
You Are (Now) Level Two
You Are (Now) Level Three"

and it should just say

"You are Level One"

Im guessing it has to do with how i put "PlayersExp=0-4);" and "PlayersExp=5-10);"...
Anybody know the problem- or even better, a fix?
thanks.

Expand|Select|Wrap|Line Numbers
  1. #include "Library.h"
  2. int PlayersExp = 0;
  3. int PlayersLevel=1;
  4.  
  5.  
  6. bool CheckLevelUp()
  7. {
  8.      if (PlayersExp=0-4);
  9.      {
  10.        cout<<"You Are Level 1\n";  
  11.  
  12.      }    
  13.      if (PlayersExp=5-9);
  14.      {
  15.        cout<<"You are (Now) Level 2\n";
  16.        PlayersLevel=2;
  17.      }
  18.      if (PlayersExp=10-19);
  19.      {
  20.        cout<<"You Are (Now) Level 3\n";
  21.        PlayersLevel=3;
  22.      }
  23. }
  24.  
Ok, first you are saying "PlayersExp=" but it should be "PlayersExp==".
Second, you are saying 0 minus four, and I assume you want to do 0 through four. You shuold try:
Expand|Select|Wrap|Line Numbers
  1. if (PlayersExp >= 0 && PlayersExp <= 4){
  2.     do stuff
  3. }
  4.  
and do that for the other levels.
Apr 29 '07 #2
JosAH
11,448 Expert 8TB
C++:
Expand|Select|Wrap|Line Numbers
  1.      if (PlayersExp=0-4);
  2.      {
  3.        cout<<"You Are Level 1\n";  
  4.  
  5.      }    
  6.      if (PlayersExp=5-9);
  7.      {
  8.        cout<<"You are (Now) Level 2\n";
  9.        PlayersLevel=2;
  10.      }
  11.      if (PlayersExp=10-19);
  12.      {
  13.        cout<<"You Are (Now) Level 3\n";
  14.        PlayersLevel=3;
  15.      }
  16. }
  17.  
You made that up yourself didn't you? Who or what gave you the idea that:
Expand|Select|Wrap|Line Numbers
  1. if (value=lo-hi);
would check whether or not value would be in the range [lo ... hi]?

It doesn't work that way; C++ evaluates lo-hi (it actually subtracts those two
values) and assigns it to 'value'. Next it checks whether or not 'value' equals
zero. In your example it doesn't, i.e. it always equals -4 so the if clause is
considered to be true so the statement is supposed to be executed. The
if statement is empty though: note the semicolon at the end of all if-clauses.

So the next statement is executed which is just an output statement. This all
happens three times in a row. The fix has been given already in the previous reply.

kind regards,

Jos
Apr 29 '07 #3
lumpybanana247
134 100+
Thanks you both, but if anyone looks at this and it wondering, i know pythons works. Thanks for like the 5th time python.
Apr 29 '07 #4
ilikepython
844 Expert 512MB
Thanks you both, but if anyone looks at this and it wondering, i know pythons works. Thanks for like the 5th time python.
You are welcome.
Apr 29 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: pwinward | last post by:
Using C++ .NET 2003 and getting: "The breakpoint will not currently be hit. No executable code is associated with this line." My app links to my static library and when I try debugging either...
7
by: Bob | last post by:
Hi, I am trying to use BULK INSERT with format file. All of our data has few bytes of header in the data file which I would like to skip before doing BULK INSERT. Is it possible to write...
2
by: Eddy Bee | last post by:
Hi there, I'm encountering an inexplicable problem with page formatting in reports. Here's the easiest way to explain it: The Detail section of my report contains two elements: And let's...
0
by: Johan | last post by:
Hi, Anyone know how to tell request.item to return non-english characters. In my example the scandiavian letters ÅÄÖåäö (AAOaao with circles and dots above) gets skiped. Here is the code in...
0
by: EC | last post by:
There are times when I use the Search utility of windows explorer to find ASPX file(s) that contains a specific word. The Search utility however skips the <script ..> </script> block in the ASPX...
3
by: lumpybanana247 | last post by:
when i use this (lets say... DPOHealth = 1 and GPOHealth = 1 then, i get to this list and it displays both of them. The thing is... if i press 1 at the prompt, it will use DPO AND ...
2
by: lumpybanana247 | last post by:
bool LevelUp() { if(PlayersLevel=1) { if (PlayersExp < 5) { } if (PlayersExp > 4) {
3
by: vegtard | last post by:
by now, you have no doupt replied to many of mine and my buddy (børntard)'s questions about our faulty programming concerning the over-complicated mega-script to design your dungeons and dragons...
2
by: Steve the Pocket | last post by:
I'm writing a heapsort program. It asks for a value for "max" and creates an array of "max" # random numbers from 1-100, and then enqueues them all into a Priority Queue. Then it asks if you want...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.