Back to the loops

Mar 18, 2015 at 4:09pm
Hey guys, I'm back.
I brought this to my little nerd group and we tried it out for the random treasure generating.

The problem happens around lines 517 and 1013.

No matter the input, the loop tries to go into "Earth" components. I had it as an elseif statement earlier, with no success.

Also, if one tries to run the program to get more than one piece of treasure and they both land on getting components, it no longer even asks if you want Earth or Celestial. It goes with the one you put in the first time, but that's a problem for another time. The first one's much more important.

Here's the link to my code.

http://pastebin.com/06z8DNFu
Mar 18, 2015 at 4:14pm
1
2
3
 else if (random > 94 & random <= 97)

else if (random > 40 & random <= 60)


Its suppose to be &&

1
2
3
4
5
6
  if (random >= 1 & random <= 20)
        {
                cout << "You get " << gold << "Gold";
        }
        else if (random > 20 & random <= 40)
        {


Same everywhere.
Last edited on Mar 18, 2015 at 4:14pm
Mar 18, 2015 at 4:21pm
The error is on line 1014:
 
                if (formal = "Earth") // Note: == instead of =  

I'd suggest that you use arrays instead of this heavy cascade of if's
Mar 18, 2015 at 4:42pm
If I attempt to use == for the formal spot, it gives me an error, stating "operand types are incompatible ("bool" and "constant char *".

I'll look into the arrays.
Mar 18, 2015 at 4:45pm
Thats because formal is a bool, cant compare it with a string.

bool formal = ""; ?? do you mean to use string? Because bool is either true or false, not whatever you're trying to do there.

change it to string formal and it should solve the problem.
Last edited on Mar 18, 2015 at 4:46pm
Mar 18, 2015 at 5:00pm
And now I'm embarrassed again. Thanks for the help. :P
I keep making the small mistakes and that's killing me.
Mar 18, 2015 at 5:02pm
We all do buddy :) Just keep working hard and you'll get better and better! Happy coding!

Feel free to post if you need any help again :)
Topic archived. No new replies allowed.