cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Coin Toss
Coin Toss
Oct 29, 2016 at 4:28pm UTC
dhan4
(1)
I need to ask the user how many times they would like to flip the coin (call the coinToss function) and make the loop execute that number of times by changing some codes. Help.
#include <iostream>
#include <time.h>
using namespace std;
void coinToss();
int main()
{
int srand(time(NULL));
for (int count = 1; count <= 10; count++)
{
coinToss();
}
system("pause");
return 0;
}
void coinToss()
{
int number = 1 + rand() % 2;
cout << (number == 1 ? "heads" : "tails") << endl;
}
Oct 29, 2016 at 7:47pm UTC
SamuelAdams
(1535)
Do you know how to ask the user for a number ?
Topic archived. No new replies allowed.