challenge 2 completed :)

+1 konstantinos sxoinas · February 4, 2015
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main()
{
   int diceRollA;
   int diceRollB;
   int diceRollC;
   int diceRollD;
   char permit1;
   char permit2;
   char permit3;
   char permit4;
   char userThink;


   printf("hello! pleaze press r whenever you want to roll a dice \n ");
   printf("roll a dice  \n");
   scanf(" %s",&permit1);

   if ( permit1 == 'r') {
       diceRollA=( rand()%6) + 1;
       printf(" %d \n",diceRollA);
   }

   printf("pleaze roll a dice for a second time \n");
   scanf(" %s",&permit2);


   if ( permit2 == 'r') {
       diceRollB=( rand()%6) + 1;
       printf(" %d \n",diceRollB);
   }
   printf("pleaze roll a dice for third time \n ");
   scanf(" %s",&permit3);
   if ( permit3 == 'r') {
       diceRollC=( rand()%6) + 1;
       printf(" %d \n",diceRollC);
   }

   printf("the sum of your rolls is %d \n",diceRollA+diceRollB+diceRollC);


   printf("now guess if your next roll is going to be higher or lower  \n ");
   printf("if you think that it will be higher  press h or if you think it will be lower press l \n");
   scanf(" %s",&userThink);

   if ( userThink == 'h') {
        printf("now press r again to roll the dice \n");
        scanf(" %s",&permit4);
        if ( permit4 == 'r'){
            diceRollD =(rand()%6)+1;
            printf(" %d \n ",diceRollD);
            if(diceRollD>diceRollC){
                printf("good job nub \n");
            }
            if(diceRollD==diceRollC){
                printf("too bad it came the same again \n");
            }
            else printf("you are truly nub \n");


        }
   }
    if( userThink == 'l') {
        printf("now press r again to roll the dice \n");
        scanf(" %s",&permit4);
        if ( permit4 == 'r'){
            diceRollD =(rand()%6)+1;
            printf(" %d \n ",diceRollD);
            if(diceRollD<diceRollC){
                printf("good job nub \n");
            }
            if(diceRollD==diceRollC){
                printf("too bad it came the same again \n");
            }
            else printf("you are truly nub \n");



   }
    }
   return 0;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 konstantinos sxoinas · February 4, 2015
/images/forum/upload/2015-02-04/25b646cfcfb1417d482414c365660a76.png
0 konstantinos sxoinas · February 5, 2015
i just posted it because in the video series bucky say that we should post it....and i am not learning by a teacher at the moment/..i am in th univrsity of electrical engineering but i learn c by bucky s videos!!!thanks for your time that you took to check my code though
0 Lazar Bulic · February 5, 2015
Well, looking from the picture your code isn't working. The sum of first rolls is 17 and when the user rolls again you just take the result of first roll and compare it to the old sum. You should do sum1 = roll1 + roll2 + roll3 and check it vs sum2 = roll4 + roll5 + roll6. Also your last check isn't working as in your case 17 != 5 but your program printfs "too bad it came same again" 
Please paste your code here http://pastebin.com/ as this formu is eating some parts of code. I can't check your code in detail.
  • 1

C

107,109 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator