+ 1

Whats the easiest and I mean easiest console game for a c++ beginner

1st Dec 2023, 9:18 AM
CerealAgenda
CerealAgenda - avatar
3 odpowiedzi
+ 2
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(static_cast<unsigned int>(time(nullptr))); int computerChoice = rand() % 3 + 1; // Random number between 1 and 3 int userChoice; cout << "Let's play Rock, Paper, Scissors!\n"; cout << "1. Rock\n2. Paper\n3. Scissors\n"; cout << "Enter your choice (1-3): "; cin >> userChoice; cout << "You chose: " << userChoice << endl; cout << "Computer chose: " << computerChoice << endl; if (userChoice == computerChoice) { cout << "It's a tie!\n"; } else if ((userChoice == 1 && computerChoice == 3) || (userChoice == 2 && computerChoice == 1) || This code Displaysthe user to input their choice (1 for Rock, 2 for Paper, or 3 for Scissors), generates a random choice for the computer, compares the choices, and determines the winner based on the game rules.
3rd Dec 2023, 7:04 AM
SUJAN
SUJAN - avatar
+ 1
//Guess 1 or 2 #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main(){ int guess{}; cout<<"Guess 1 or 2\n"; cin>>guess; cout<<"Your guess is "<<guess<<'\n'; srand (time(nullptr)); int flip = (rand()%2) + 1 ; if(guess==flip) cout<<"You win\n"; else cout<<"You lose.\n"; cout<<"It is "<<flip<<'\n'; }
2nd Dec 2023, 3:06 AM
Bob_Li
Bob_Li - avatar