Seperating two output lines by a certain number
Mar 5, 2014 at 5:54am UTC
This is my code, I have everything done and all I need to do is figure out how to get my outputs of HTHTH to 10 per line. I cant figure it out and its driving me crazy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#include<iostream>
#include<cstdlib>
using namespace std;
int tossingCoin();
int main ()
{
int coin, num, tails = 0, heads = 0;
for (num = 1; num <= 20; num++)
{
coin = tossingCoin ();
if (coin==0)
{
cout<<"T " ;
tails = tails + 1;
}
else if (coin==1)
{
cout<<"H " ;
heads = heads + 1;
}
}
cout<<endl;
cout<<"Heads: " << heads<<endl;
cout<<"Tails: " <<tails<<endl;
}
int tossingCoin()
{
return rand( )%2;
}
Mar 5, 2014 at 6:07am UTC
1 2 3 4 5 6 7 8 9 10
for (num = 1; num <= 20; num++) {
coin = tossingCoin ();
/*...
*...
*/
heads = heads + 1;
}
if (num % 10 == 0)
std::cout << std::endl;
}
Mar 5, 2014 at 6:13am UTC
Thank you so much, You reminded me of a lesson we did weeks ago!! kudos my friend
Topic archived. No new replies allowed.