03-01-2009, 17:20
|
|
|
|
חבר מתאריך: 10.10.06
הודעות: 64
|
|
משחק הגפרורים ב- C
[התמונה הבאה מגיעה מקישור שלא מתחיל ב https ולכן לא הוטמעה בדף כדי לשמור על https תקין: http://www.zix.co.il/images/z-997310587.JPG]
[התמונה הבאה מגיעה מקישור שלא מתחיל ב https ולכן לא הוטמעה בדף כדי לשמור על https תקין: http://www.zix.co.il/images/z-1393566962.JPG]
הבעיה היא עם החלק המסומן באדום, כשאני מכניס קלט לתכנית שלי זה לא מבקש שוב פעם להכניס קלט אלא מסיים שם ומשום מה קשה לי לשים את האצבע על איפה הבעיה בקוד. אולי אתם רואים את זה?
קוד PHP:
#include<stdio.h> #include <stdlib.h>
int main () { int n,k,ct,t=0; printf("Enter a number of matches: \n"); scanf("%d",&n); while (n<5) { printf("Invaild game. \n"); printf("Enter a number of matches: \n"); scanf("%d",&n); } while (n > 1) { printf("There are %d matches left. \n",n); printf("Enter the amount you take: \n"); scanf("%d",&k); while(!(k>0 && k<4)) { printf("Invaild number of matches.\n"); scanf("%d",&k); } t = 1; n -= k; if (n > 1) { t = 0; switch (n%4) { case 1: case 2: ct = 1; break; case 3: ct = 2; break; case 4: ct = 3; break; } }
printf("The computer takes %d matches.\n", ct); n -= ct; } printf("There is 1 match left.\n"); if (t==1) { printf ("Congratulations! You win!\n"); } else { printf ("You lose!\n"); } return 0; system("PAUSE"); }
|