🌿 Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms"

Image
  🌿  Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms" 🧭  1. Introduction: Farming in the Age of Climate Change In a world where clean water is more precious than gold, efficient  rainwater harvesting and plant care systems  are no longer optional — they’re essential. Smart farming doesn’t mean just automating irrigation. It means combining  robotic drones, environmental sensors, and intelligent scheduling  to build a garden that practically takes care of itself. In this guide, we build a  fully functional Garden Manager System  using  C++  that: Captures and conserves rainwater Uses  robotic drones and sensors  to monitor crop health Integrates a  real-time UI  with progress bars and alerts Includes  timers  for scheduling plant growth and drone tasks Plays  interactive sounds  based on crop state and events Whether you'r...

C++ Mini Projects for Beginners:

C++ Mini Projects for Beginners: Number Guessing Game

Hi guys and back with you with another cool project on c++. I hope you enjoyed the last project and gained some valuable skills from it. Now let's continue on building another project. 

This is going to be a number guessing game where the program generates a random number, and the user has to guess it. The program gives hints like "too high" or "too low.".

The skills you will learn and practice during this project will be random number generation, loops, conditional statements and more. So without any further delay let's get started!

Detailed description about the project 

This project takes a random number from a particular range, e.g., 1 up to 100.

User's task
The user tries to guess what the number is.

Program behavior
The program gives hints after every guess.

Hint: Too big
If the guess is bigger than the number.

Hint: Too small
If the guess is smaller than the number.

Game duration
The game goes on until the user makes the successful guess.

Here is the code to write the desired program. 

#include <iostream>
#include <cstdlib> // For rand() and srand()
#include <ctime> // For time()

using namespace std;

int main() {
    // Initialize random seed
    srand(time(0));

    // Generate a random number between 1 and 100
    int randomNumber = rand() % 100 + 1;
    int userGuess;
    int attempts = 0;

    cout << "Welcome to the Number Guessing Game!\n";
    cout << "I have chosen a number between 1 and 100.\n";
    cout << "Try to guess it!\n";

    // Game loop
    while (true) {
        cout << "Enter your guess: ";
        cin >> userGuess;
        attempts++;

        // Check the user's guess
        if (userGuess > randomNumber) {
            cout << "Too high! Try again.\n";
        } else if (userGuess < randomNumber) {
            cout << "Too low! Try again.\n";
        } else {
            cout << "Congratulations! You guessed the number in " << attempts << " attempts.\n";
            break;
        }
    }

    return 0;
}


### How the game works

- **srand(time(0))**: Generate a random number according to the current time each time the game runs.
- **rand() % 100 + 1**: Gives any number from 1 up to 100.

### User input
The user gives input by entering `cin >> userGuess`.

### Loop used by the game
A `while true` loop is used continuously to accept all the guesses.

- When the guess is too big, the output is "too big".
- When the guess is too small, the output is "too small".
- If the user guesses correctly, the loop breaks, and the program ends.
- The variable called `attempts` keeps count of how many times the user has made guesses.

### Sample of running the program

```
Welcome to the Number Guessing Game!
I have chosen a number between 1 and 100.
Try to guess it!
Enter your guess: 50
Too low! Try again.
Enter your guess: 75
Too high! Try again.
Enter your guess: 62
Too high! Try again.
Enter your guess: 56
Congratulations! You guessed the number in 4 attempts.
```

### Skills used in the program

- **Generation of random numbers**: Using `rand()` and `srand()`.
- **While loop**: To ensure the program runs until the correct guess is made.
- **Conditional statements**: `if`, `else if`, and `else` statements for giving feedback to the user.
- **Input and output statements**: `cin` for user input and `cout` for message display.

That's it we have built a nice game using a very on skills! You can show it to your friends your family and also make them believe that you are not too much of a beginner now you can handle such little games on your own now.

Enjoy!


Comments

Popular posts from this blog

C++ Projects: Basic Traffic Management System

C++ Projects: Book Shop Management System

C++ Projects: Password Manager