-1

これが私のコードです:

#include <cs50.h>
#include <stdio.h>
#include <strings.h>

int main(void)
{
    int answer_compared;

    do  {
        printf("What is your credit card number?\n");
        long long credit_card = GetLongLong ();
        printf("Is your credit card number is %lld?\n", credit_card);
        printf("Please respond Yes or No.\n");
        string answer = GetString ();
        answer_compared = strncasecmp(answer, "y", 1);
    } while (answer_compared != 0);
    int long long cc = credit_card;
    printf("Thank you.\n"); 
    if (cc == 4){
        printf("Visa\n");
    }else if (cc == 34 || cc == 37){
        printf("AMEX\n");
    }else if (cc >= 51 && cc <= 55){
        printf("MC\n");
    }else printf("You did not enter an appropriate credit card.\n");
        printf("I think this is what I need.\n");

}              

私のエラーは次のとおりです。

credit.c:17:32: error: use of undeclared identifier 'credit_card'
        int long long cc = credit_card;
                           ^

もともと、私はすべての cc 変数を credit_card に設定していましたが、同じ理由でさらに 5 つのエラーが追加されたため、変更しました。do-while ループ内での変数の作成について説明している場所を見つけようとしましたが、役に立ちませんでした。

ここで何が問題なのか説明できますか?

4

3 に答える 3

0

定義する必要があります

long long credit_card

do while ループの外側

于 2014-02-09T13:47:49.423 に答える