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();
}
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' );