+ 1
Whats the easiest and I mean easiest console game for a c++ beginner
3 Respuestas
+ 3
Do you mean to program? Something like pong or snake...
https://www.sololearn.com/discuss/795901/?ref=app
https://www.sololearn.com/discuss/3196811/?ref=app
https://www.sololearn.com/discuss/2099115/?ref=app
https://www.sololearn.com/discuss/1504394/?ref=app
https://www.sololearn.com/discuss/2278671/?ref=app
https://www.sololearn.com/discuss/3077696/?ref=app
https://www.sololearn.com/discuss/2230956/?ref=app
https://www.sololearn.com/discuss/1476409/?ref=app
https://www.sololearn.com/discuss/196077/?ref=app
+ 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.
+ 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';
}