lundi 22 juillet 2019

How do you set up the syntax for a random number generator using cpp?

Let me preface by saying I am very new to coding but enjoy learning. I want to randomly generate a number then follow with 700 if statements that will ask a question according to what number is generated. So from the user pov it will randomly ask questions and then will generate another number after.

I've tried the timing random number generators. I can't seem to get rand operator to work. I just want a super basic generator.

#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
string a = "placeholder";
cout << "Welcome to Basic Strategy Practice" << endl;
cout << "You are given two aces and the dealer is showing a four. Hit, 
double, or split?" << endl;
cin >> a;
if (a == "split"){
    cout << "Correct!" << endl;
}
else {
    cout << "Incorrect" << endl;
}


return 0;
}

Basically, I would encapsulate the above code in an if statement that specifies which number was generated after each question is asked. I would think you would just put the if statement inside a while loop of some sort. Thanks!




Aucun commentaire:

Enregistrer un commentaire