/*Download:aufdo.c*/
#include <stdio.h> #include <stdlib.h> #include <time.h>
/*PROTOTYPEN*/ void wieweitentf(int,int); void maxzahl(int, int);
void maxzahl(int rate, int zuf) {
(rate>zuf) ?wieweitentf(rate,zuf) :wieweitentf(zuf,rate); }
void wieweitentf(int a, int b) {
int tmpcount=0;
while(a>b) {
b++; tmpcount++; }
if(tmpcount==1) printf("Gaaaanz knapp!!!!\n");
else if(tmpcount==2) printf("Nicht schlecht, ziemlich nah dran!!\n");
else printf("Spielen sie heute besser nicht Lotto ;)\n"); }
int main(void) {
char jn; int ratezahl,count,erraten; time_t t; /*Für Zufallszahl srand()*/ int zufall;
do{
count=0; erraten=0; srand((unsigned) time(&t)); zufall=rand()%10;
do{
printf("Zahleingabe bitte (1-10): "); scanf("%d",&ratezahl); if(ratezahl==zufall) {
erraten=1; count++; } else {
maxzahl(ratezahl,zufall); count++; } }while(erraten!=1 && count !=3);
if(count==3) {
if(erraten==1) {
printf("Schade jetzt wäre die Zahl richtig gewesen!\n"); printf("Leider haben sie zuviele Versuche benötigt.\n"); } else {
printf("Sie haben 3 Chancen vertan ;)\n"); printf("Die Zahl wäre %d gewesen!!\n",zufall); } } else printf("Wow mit %d Versuche erraten!\n",count); fflush(stdin); printf("Noch ein Versuch (j/n) : "); scanf("%c",&jn); fflush(stdin); }while(jn!='n'); printf("\n\n\t\tBYE !!!\n"); return 0; }
|