Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

(For beginners in c++) Correct my code!

+6 votes
asked May 21, 2023 by Eidnoxon (5,110 points)
https://onlinegdb.com/B0OgykA3X

Sorry if I have gave you some hard challange, but I'm trying to improve your skills. Hope this helped :D

3 Answers

+1 vote
answered May 22, 2023 by Coder (160 points)
cout<<"hello world";
+3 votes
answered May 22, 2023 by Sacha Bugnon (240 points)
#include <iostream>
using namespace std;

void surprise() {
    cout << "HELLO " << "Guesser" << "!!! :D";
}

int main() {
    int guess;
    int num_of_guess = 1;
    int randm_num = rand() % 10 + 1;
    do {
        cout << "Enter here a number:";
        cin >> guess;
        if(guess > randm_num){
            cout << "Lower" << endl;
            num_of_guess++;
        } else if(guess < randm_num){
            cout << "Bigger" << endl;
            num_of_guess++;
        } else {
            cout << "Bingo! it took you exactly " << num_of_guess << " guesses." << endl;
            break;
        }
    } while (1);
    surprise();
}
commented May 28, 2023 by Eidnoxon (5,110 points)
Great job! :D
0 votes
answered May 29, 2023 by Abdul Hayee (180 points)
#include <iostream>

int main() {
  int num;
  int guess;
  int num_of_guess = 0;
  int randm_num = rand() % 10 + 1;

  do {
    std::cout << "Enter a number: ";
    std::cin >> guess;

    if (guess > randm_num) {
      std::cout << "Lower\n";
    } else if (guess < randm_num) {
      std::cout << "Higher\n";
    } else {
      std::cout << "Bingo! It took you " << num_of_guess << " guesses.\n";
      break;
    }

    num_of_guess++;
  } while (guess != randm_num);

  surprise();

  return 0;
}

void surprise() {
  std::cout << "HELLO " << name << "!!! :D";
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...