Back to the loops

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
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
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
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.
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
And now I'm embarrassed again. Thanks for the help. :P
I keep making the small mistakes and that's killing me.
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.