C++ Novice. Could someone please tell me how I would go about using an array in this program. Thanks!


[int main()
{

int choice, compchoice;

//The do-while loop repeats the program until there is a winner

do
{

// Assigning variables and introduction to the game

srand ((unsigned)time(0));

compchoice = (rand()%2)+1;

cout << "Welcome to Rock, Paper, Scissors! Let's Play!\n\n";

cout << "Type 1 for rock, 2 for paper, or 3 for scissors\n\n";
cin >> choice;

// If and else if statements if #1 is chosen for Rock

if (choice == 1)

{
if (compchoice == 1)
cout << "The computer also chose rock, tie Game, try again!\n\n";
else if (compchoice == 2)
cout << "The computer chose paper and paper covers rock! You Lost! )-:\n\n";
else if (compchoice == 3)
cout << "The computer chose scissors and rock smashes scissors! You won! (-:\n\n";
}

// If and else if statements if #2 is chosen for Paper

if (choice == 2)

{
if (compchoice == 2)
cout << "The computer also chose paper, tie Game, try again...\n\n";
else if (compchoice == 1)
cout << "The computer chose rock and paper covers rock! You won! (-:\n\n";
else if (compchoice == 3)
cout << "The computer chose scissors and scissors cuts paper! You lost! )-:\n\n";
}

// If and else if statements if #3 is chosen for Scissors

if (choice == 3)
{
if (compchoice == 3)
cout << "The computer also chose scissors, it's a tie, try again!\n\n …
else if (compchoice == 2)
cout << "The computer chose paper and scissors cuts paper! You won! (-:\n\n";
else if (compchoice == 1)
cout << "The computer chose rock and rock smashes scissors! You Lost! )-:\n\n";
}

//The do-while loop repeats the program until there is a winner

} while(choice == compchoice);

return 0;
}[code]int main()
{

int choice, compchoice;

//The do-while loop repeats the program until there is a winner

do
{

// Assigning variables and introduction to the game

srand ((unsigned)time(0));

compchoice = (rand()%2)+1;

cout << "Welcome to Rock, Paper, Scissors! Let's Play!\n\n";

cout << "Type 1 for rock, 2 for paper, or 3 for scissors\n\n";
cin >> choice;

// If and else if statements if #1 is chosen for Rock

if (choice == 1)

{
if (compchoice == 1)
cout << "The computer also chose rock, tie Game, try again!\n\n";
else if (compchoice == 2)
cout << "The computer chose paper and paper covers rock! You Lost! )-:\n\n";
else if (compchoice == 3)
cout << "The computer chose scissors and rock smashes scissors! You won! (-:\n\n";
}

// If and else if statements if #2 is chosen for Paper

if (choice == 2)

{
if (compchoice == 2)
cout << "The computer also chose paper, tie Game, try again...\n\n";
else if (compchoice == 1)
cout << "The computer chose rock and paper covers rock! You won! (-:\n\n";
else if (compchoice == 3)
cout << "The computer chose scissors and scissors cuts paper! You lost! )-:\n\n";
}

// If and else if statements if #3 is chosen for Scissors

if (choice == 3)
{
if (compchoice == 3)
cout << "The computer also chose scissors, it's a tie, try again!\n\n …
else if (compchoice == 2)
cout << "The computer chose paper and scissors cuts paper! You won! (-:\n\n";
else if (compchoice == 1)
cout << "The computer chose rock and rock smashes scissors! You Lost! )-:\n\n";
}

//The do-while loop repeats the program until there is a winner

} while(choice == compchoice);

return 0;
}]
Last edited on
before i read it, please click edit on your post, find the format section click the <> button and put your code between the code blocks
but to do a char array just do char var_name [byte_size]
Thanks, I'm new to all of this and I really appreciate the help.
however unless you are using pointers use #include <string> which gives you the ability to have string var_type which is the same as the char array
Topic archived. No new replies allowed.