I need code for C++ to say "Hello World!"
- User
I need code for C++ to say "Hello World!"
- Assistant
Here is a simple code snippet in C++ to say "Hello World!":
#include <iostream> int main() { std::cout << "Hello World!" << std::endl; return 0; }When you run this code, it will display "Hello World!" on the console.
- User
I need C++ code for the Bunny Game.
- Assistant
Sure! Here's a simple implementation of the Bunny Game in C++:
#include <iostream> #include <cstdlib> #include <ctime> int main() { // Seed the random number generator srand(time(nullptr)); // Generate a random number between 1 and 100 int randomNumber = rand() % 100 + 1; std::cout << "=== Welcome to the Bunny Game! ===" << std::endl; std::cout << "Guess the number between 1 and 100!" << std::endl; int guess; int attempts = 0; do { std::cout << "Enter your guess: "; std::cin >> guess; attempts++; if (guess > randomNumber) { std::cout << "Too high!" << std::endl; } else if (guess < randomNumber) { std::cout << "Too low!" << std::endl; } else { std::cout << "Congratulations! You found the bunny in " << attempts << " attempts." << std::endl; } } while (guess != randomNumber); std::cout << "Thank you for playing the Bunny Game!" << std::endl; return 0; }In this game, the player needs to guess a random number between 1 and 100. After each guess, the program will provide feedback on whether the guess was too high or too low. The game continues until the player guesses the correct number. The program also keeps track of the number of attempts it took the player to find the correct number.
- User
Write a program that creates a linked list of bunny objects. Each bunny object must have
Sex: Male, Female (random at creation 50/50) color: white, brown, black, spotted age : 0-10 (years old) [with the exception of mutant bunnies (0-50)] Name : randomly chosen at creation from a list of bunny names. radioactive_mutant_vampire_bunny: true/false (decided at time of bunny creation 2% chance of true) At program initialization 5 bunnies must be created and given random colors. Each turn afterwards the bunnies age 1 year. So long as there is at least one male age 2 or older, for each female bunny in the list age 2 or older; a new bunny is created each turn. (i.e. if there was 1 adult male and 3 adult female bunnies, three new bunnies would be born each turn) New bunnies born should be the same color as their mother. If a bunny becomes older than 10 years old, it dies [with the exception of mutant bunnies, which can become 50 years old]. If a radioactive mutant vampire bunny is born then each turn it will change exactly one non radioactive bunny into a radioactive vampire bunny. (if there are two radioactive mutant vampire bunnies two bunnies will be changed each turn and so on...) Radioactive vampire bunnies are excluded from regular breeding and do not count as adult bunnies. Radioactive vampire bunnies do not die until they reach age 50. The program should print a list of all the bunnies in the colony each turn along w/ all the bunnies details, sorted by age. The program should also output each turns events such as Bunny Thumper was born! Bunny Fufu was born! Radioactive Mutant Vampire Bunny Darth Maul was born! Bunny Julius Caesar died! The program should write all screen output to a file. When all the bunnies have died the program terminates. If the bunny population exceeds 1000 a food shortage must occur killing exactly half of the bunnies (randomly chosen) - Assistant