Challenge #2 My way

+1 Rolandas Seacret · August 21, 2014
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main()
{

    srand((unsigned)time(NULL));        // bucky did not mention it but without it computer would not select random numbers
    int counter,rolling,answer,finall;  //all variables
    char choice;
    answer = 0;   //answer and finall are set to 0 for purpose not to mess up calculation
    finall = 0;

    for (counter =1; counter<=3;counter++){         //generating random numbers and add them to answer
        rolling = ( rand()%6 ) +1;
        printf("your %d roll was %d \n",counter,rolling);
        answer = answer + rolling;
    }
    printf("Your total from 3 dices is %d \n",answer);   //shows the answer
    printf("Do you think your next roll will be higher(h),lower(l) or same(s) as your current total? \n"); //asks for user to input 1 letter

    scanf(" %c",&choice); //gets user input

    rolling = ( rand()%6 ) +1;  //generates new number

    if(choice == 'l' || choice == 'h'|| choice == 's' ){    //this if statement checks if user inputed l/s/h letter
        finall = 1;
    }else{
        finall = 0;
    }

    if(choice == 'l' && rolling <answer && finall > 0){                                                //and this if statement is kinda clear :)
        printf("Congratz you guessed right last number %d is lower then your total %d",rolling,answer);
    }else if(choice == 's' && rolling == answer && finall > 0){
        printf("Congratz you guessed right last number %d is same as your total %d",rolling,answer);
    }else if(choice == 'h' && rolling > answer && finall > 0){
        printf("Congratz you guessed right last number %d is higher then your total %d",rolling,answer);
    }else if (finall == 0){
        printf("Go away BOTTTTTEEEERRRRR you messed up badly read text next time");
    }else{
        printf("Go away fucker you messed up badly your last number was %d",rolling);
    }


    return 0;
}



Post a Reply

Replies

Oldest  Newest  Rating
0 Rolandas Seacret · August 24, 2014
:)
0 Jacobs . · August 24, 2014
After seeing some other bucky's C videos i realized that "blank string feature", so you can add option for user inputing nothing. The program wouldn't stop at blank input :)
0 Rolandas Seacret · August 23, 2014
Oh ye didint saw that ty for seeing that :)
0 Jacobs . · August 23, 2014
Actually current version does not continue as well. Program still needs some input anyways.
0 Rolandas Seacret · August 23, 2014
Thank you for your suggestion it would work. :) But if user does not enter anything the program will not continue. So there is no difference its only choice of programming way. Thank you for your criticize/ offer i will keep it in mind ;) next time :)
0 Jacobs . · August 23, 2014
Hi, this challenge is fine, but i would enhance it a little bit.

This piece of code:

if(choice == 'l' || choice == 'h'|| choice == 's' ){ //this if statement checks if user inputed l/s/h letter 
finall = 1;
}else{
finall = 0;
}

Could be replaced by do while statement. When user doesnt input l,s or h computer will say something like "You messed it up, try again - insert l/h/s for this this and this etc.." and the program wouldn't stop immediately :)
  • 1

C

107,323 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator