忍者ブログ

JinX_Yui Blog

i think she is a milf...

2025.08│ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

ボーリングのスコア計算(C言語で)

10/30 の課題:

ボーリングの点数計算を行うプログラムを作成する。
1投ごとに倒数を入力し、全て入力し終えたらトータルスコアを表示する。

スペア、ストライクによって点数計算が変わる。
スペアの場合は、次の倒数を加算する。
ストライクの場合は、次とその次の倒数を加算する。

10フレーム目は、2投した段階で、スペア、ストライクであれば、3投目を行うことができる。
10フレーム目は総倒数がそのまま点数となる。

#include <stdio.h>

int main(void){

    int th1,th2,th3;
    int sc=0, sc2=0;
    int total=0;
    int fr;

    for(fr=1 ; fr<=9 ; fr++){

        printf("[%d]\n",fr);

        printf("1投目:");
        scanf("%d",&th1);

        /* error */
        if(th1<0 || th1>10){
            printf("error!!!\n\n");
            fr--;
            continue;
        }

        if(th1 != 10){
            printf("2投目:");
            scanf("%d",&th2);

            /* error */
            if(th2<0 || th1+th2>10){
                printf("error!!!\n\n");
                fr--;
                continue;
            }
        }

        if(sc != 0){
            total += th1;
            sc--;
            if(th1!=10 && sc != 0){
                total += th2;
                sc--;
            }
        }
        if(sc2 != 0){
            total += th1;
            sc2--;
            if(th1!=10 && sc2 != 0){
                total += th2;
                sc2--;
            }
        }
       
        total += th1;
        if(th1 != 10){
            total += th2;
        }

        if(th1!=10 && (th1+th2 == 10)){
            sc=1;
        }else if(th1 == 10){
            if(sc == 1){
                sc2 = 2;
            }
            if(sc2 != 2){
                sc =2;
            }
        }
    }


    /* 10 times */
    while(1){
        printf("[10]\n");

        printf("1投目:");
        scanf("%d",&th1);

        /* error */
        if(th1<0 || th1>10){
            printf("error!!!\n\n");
            continue;
        }

        printf("2投目:");
        scanf("%d",&th2);

        /* error */
        if(th1<10 && (th2<0 || th1+th2>10)){
            printf("error!!!\n\n");
            continue;
        }else if(th1==10 && (th2<0 || th2>10)){
            printf("error!!!\n\n");
            continue;
        }

        if(th1+th2>=10){
            printf("3投目:");
            scanf("%d",&th3);

            /* error */
            if((th2==10 || th1+th2==10) && (th3<0 || th3>10)){
                printf("error!!!\n\n");
                continue;
            }else if(th2<10 && (th3<0 || th2+th3>10)){
                printf("error!!!\n\n");
                continue;
            }
        }

        if(sc != 0){
            total += th1;
            sc--;
            if(sc != 0){
                total += th2;
                sc--;
            }
        }
        if(sc2 != 0){
            total += th1;
            sc2--;
            if(sc2 != 0){
                total += th2;
                sc2--;
            }
        }

        total += (th1+th2);
        if(th1+th2>=10){
            total += th3;
        }

        break;
    }

    printf("\ntotal:%d\n",total);
    return 0;
}
PR
*COMMENT-コメント-
*COMMENT FORM-コメント投稿-
  • この記事へのコメント投稿フォームです。
Name:
Title:
Mail:
Url:
Color:
Decoration: Vodafone絵文字 i-mode絵文字 Ezweb絵文字
Message:
Pass: ※編集時に必要です。
Secret:  ※チェックすると管理者へのみの表示となります。 
*TRACKBACK-トラックバック-
  • この記事のURLとトラックバックURLです。
  • 必要に応じてご使用くださいませ。
この記事のURL▼
この記事のトラックバックURL▼
■プロフィール
HN:
刄拔 ゆい
性別:
男性
職業:
SE
趣味:
読書、妄想
自己紹介:
SE and 塾講師
■最新CM
■最新TB
■フリーエリア
■ブログ内検索
■カレンダー
07 2025/08 09
S M T W T F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
■アーカイブ
■バーコード