Opiszę w punktach na czym polega zadanie programu:
- wylosowanie 3 cyfr, dodanie ich do siebie i ulokowanie informacji w "suma1", taka sama procedura dla "suma2"
- zadeklarowanie, czy suma z kolejnego losowania będzie H-większa, L-mniejsza lub S-taka sama jak w losowaniu pierwszym
- porównanie wyników i wyświetlenie komunikatu "Good" lub "Wrong"
Niezależnie od wartości sum otrzymuję losowe komunikaty, które nie pokrywają się z prawdą (np. suma2 była większa, zadeklarowałem H, a mimo to otrzymuję "Wrong")
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
int main()
{
int a;
char x;
srand (time(0));
int rzut1, rzut2;
int suma1=0, suma2=0;
for( a=0; a<3; a++ ){
rzut1 = (rand()%6) + 1;
suma1 += rzut1;
}
for( a=0; a<3; a++ ){
rzut2 = (rand()%6) + 1;
suma2 += rzut2;
}
printf("The sum of first three rolls is %d\n\n", suma1);
printf("Guess if the next sum will be higher, lower or the same as in the first roll (type H, L or S): ");
scanf("%c", &x);
if(x='H'){
if(suma2>suma1){
printf("\nGood! The second sum is %d", suma2);
}else{
printf("\nWrong! The second sum is %d", suma2);
}
}else if(x='S'){
if(suma2==suma1){
printf("\nGood! The second sum is also %d", suma2);
}else{
printf("\nWrong! The second sum is %d", suma2);
}
}else if(x='L'){
if(suma2<suma1){
printf("\nGood! The second sum is %d", suma2);
}else{
printf("\nWrong! The second sum is %d", suma2);
}
}
return 0;
}