If statement overusage?

This is a discussion on If statement overusage? within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm a n00b and have been doing the tutorials and I have many questions and you'll rpbably find me ...

If statement overusage?

Hi, I'm a n00b and have been doing the tutorials and I have many questions and you'll rpbably find me annoying because I really ask alot of questions daily. At the moment I have 3, I'm just gonna quote them cause I posted them on a pretty much dead board.

I was making a rock paper scissors game and suddenly realised I had about 15 if statements and realised that this can't be the way your meant to do it. Is there another way to do it? or is it all done with if and else statements?

When I was making all those if statements I wondered how you close a program? I know that it stops when you get to the bottom but how do you tell it to close after the users presses enter at a certain point, say in a if statment?

Someone told me that this is how you make x a random number srand(time(0));
int x = rand();

But I have no idea where I'm mean to put it? Where do I put it?

By the way, I'm up to lesson 9 on the tutorials if that means anything?

If you in this piece of code input 1 output will be:
a = 1
If you input 2 ouput will be:
a = 2
a = 0
If you input something else output will be:
Default action taken.

Basicly the program will just start at the first case that matches and then it will go through all the other cases (even if they arent correct) and do what is in those until it hits a break or until no more cases are given.

1) If you're testing the same integerer value a lot, you can use a siwtch / case statement. Chars can also be tested. Other than that, if / else statements are fine.

2) If you're in your main function, just return a value (make sure you're using int main and not void main) and that'll be it.

3) Look in the FAQ, it shows you how to do random numbers. You need to seed the generator once before you assign random numbers. AS for WHEN you use rand(), just the same place as you would if you assigning some other value to it. Also make sure you do it after you use srand(). See the FAQ...