what is wrong with this?

what am i doing wrong? and how can i add a "do u want to continue option at the end" Y or N ??

Error 1 error C2440: 'initializing' : cannot convert from 'void'to 'int'
and it says "illegal" else without matchin if?????

im kind of new to this sorry

#include <iostream>
#include <time.h>
#include <ctime>
#include <cstdlib>
using namespace std;

int main()
{

int (3.0*rand()/float(RAND_MAX));
int choice;
int compchoice = srand(unsigned(time(NULL))); rand();
cout << "Enter Your Move <R=Rock, P=Paper, S=Scissors>: ";
cin >> choice;

// Choice by user is rock
if (choice == 0)
{
if (compchoice == 0)
cout << "I picked Rock ";
cout << "Tie ";
else if (compchoice == 1)
cout << "I picked Paper ";
cout << "I win! ";
else if (compchoice == 2)
cout << "I picked Scissors ";
cout<< "You win! ";
}
//Choice by user is Paper
if (choice == 1)
{
if (compchoice == 0)
cout << "I picked Rock ";
cout << "You win! ";
else if (compchoice == 1)
cout << "I picked Paper ";
cout << "Tie ";
else if (compchoice == 2)
cout << "I picked Scissors ";
cout << "I win! ";
}
//Choice by user Scissors
if (choice == 2)
{
if (compchoice == 0)
cout << "I picked Rock ";
cout << "I win! ";
else if (compchoice == 1)
cout << "I picked Paper ";
cout << "You win! ";
else if (compchoice == 2)
cout << "I picked Scissors ";
cout << "Tie ";
}
return main();
}
The nested if statements need braces too as they contain more than one statement.

You're calling main recusively at the end.
Last edited on
oh culd u show me how please like where shuld the braces go
what do u mean by im calling main recusively at the end? im just learning sorry
Remember that without braces, only the first statement after the if statement will be executed. Also you need to remove return main();. int main() must return a 0. If you want to create a main game loop than enclose the if statements within a do...while() loop and ask the user if they would like to continue playing, for example:

1
2
3
4
do
{
    // if statements
} while( playAgain == 'N' );
Simply put, a recursive function is a function that calls itself, which is indicated by your line return main();
to do the <Y,N> option (y to continue and n to exit)
? im not getting it soo if the user say no and wants to exit how would it look
For example:
1
2
3
if (compchoice == 0)
cout << "I picked Rock ";
cout << "I win! ";

should be
1
2
3
4
5
if (compchoice == 0)
{
    cout << "I picked Rock ";
    cout << "I win! ";
}


At the end, simply use return 0;
Topic archived. No new replies allowed.