fork download
  1. //OrinTill Qimid CS1A Chapter 4, P. 294, 4
  2. //
  3. /**************************************************************
  4.  * Coint Flips
  5.  *
  6.  * ____________________________________________________________
  7.  * This program simulates a coin toss
  8.  * ____________________________________________________________
  9.  * INPUT
  10.  * flip: amount of times the coin is fliped
  11.  * OUTPUT
  12.  * ran: The result
  13.  **************************************************************/
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cmath>
  17. using namespace std;
  18. float num();
  19.  
  20.  
  21. int main()
  22. {
  23.  
  24. num();
  25.  
  26. }
  27. float num()
  28. {
  29. int flip;
  30. int ran;
  31. cout<<"how manytimes do you want to flip the coin?"<<endl;
  32. cin>>flip;
  33. for (int i = 1; i <=flip ; i++)
  34. {
  35. ran = rand() % 2+1;
  36. if (ran==1)
  37. {
  38. cout<<"It's head"<<endl;
  39. }
  40. if (ran==2)
  41. {
  42. cout<<"It's tail"<<endl;
  43. }
  44. }
  45.  
  46.  
  47. return ran;
  48. }
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
Standard output is empty