My student number: s134099 Start! xoooooooooooooo Dice: 3 oooxooooooooooo Dice: 4 oooooooxooooooo Dice: 5 ooooooooooooxoo Dice: 6 Too large to go. Cast dice again! Dice: 2 oooooooooooooox Goal! ----------------------- |
Start! と,ゴールしたときの絵は反復処理を使用しないで,以下のように出力すれば結構です.
printf("Start! "); printf("xoooooooooooooo\n\n"); ......... printf("oooooooooooooox\n"); printf("Goal!\n\n");
/* ************************************************** */ /* */ /* プログラミング入門 情報科学演習C7 */ /* レポート課題 */ /* 2013.12.09 */ /* */ /* ************************************************** */ /* */ /* 学生番号: */ /* */ /* 氏名: */ /* */ /* ************************************************** */ /* */ /* この行以降に解答のプログラムを書くこと */ #include <stdio.h> #include <stdlib.h> #include <time.h> main() { srand((unsigned) time(NULL)); int i, p = 1, dice; printf("My student number: s134099\n\n"); printf("Start! "); printf("xoooooooooooooo\n\n"); while(p<15){ dice = rand() % 6 + 1; printf("Dice: %d ", dice); p += dice; if(p>15){ printf("Too large to go. Cast dice again!\n\n"); p -= dice; } else if(p==15){ printf("oooooooooooooox\n"); printf("Goal!\n\n"); } else{ i = 1; while(i<=15){ if(i==p) printf("x"); else printf("o"); i++; } printf("\n\n"); } } printf("-----------------------\n\n"); return(0); } |