Challenge #2 |Suggestions??|

+1 Afro Anon · October 23, 2015
#include <stdio.h>
#include <math.h>
#include <time.h>

int main()
{
    int i;
    int diceRoll;
    int result1;
    int sum1=0;
    char guess;


    for(i=0; i< 3; i++)
    {  
        srand(time(NULL));
        result1=(rand()%6)+1;
        sum1+=result1;
    }
    printf("%d\n", sum1);

    scanf( "%c", &guess);
    int sum2=0;
    int result2;
    for(i=0; i< 3; i++)
    { 
        srand(time(NULL));
        result2=(rand()%6)+1;
        sum2+=result2;
    }
    printf("%d", sum2);

    if(sum2>sum1&&guess=='h')
    {
        printf("\nCool Man\n");
    }

     else if(sum1>sum2&&guess=='l')
    {
        printf("\nCool Man\n");
    }

     else if(sum2==sum1&&guess=='s')
    {
        printf("\nCool Man\n");
    }

    else
    {
        printf("\nYou Suck\n");
    }


    return 0;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Cristiano Cappagli · October 23, 2015
I think it works fine ;)
Personal preference: I would add more space when doing math operations, or inside loops, it helps you reading your code easier :) Like this:

    for(i = 0; i < 3; i++){
        srand(time(NULL));
        result1 = (rand() % 6) + 1;
        sum1 += result1;
    }
0 Afro Anon · October 23, 2015
Thanks :) I'll keep that in mind 
0 Cristiano Cappagli · October 24, 2015
You're welcome ;)
  • 1

C

107,041 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator