Helllo字符串語句,我還是新的編程,有一個問題有關,而使用用戶輸入與我進行了我似乎無法找到我在做什麼研究使用if語句錯誤? 以下是我發佈的簡單乘法計算器。如果使用帶有字母和用戶輸入
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
int a ;
int b ;
int c ;
printf("\n");
printf("\n");
printf("Welcome to calculator");
printf("\n");
printf("\n");
printf("what would you like to choose for first value?");
scanf("%d", &a);
printf("\n");
printf("What would you like to input for the second value?");
scanf("%d", &b);
c = a * b;
printf("\n");
printf("\n");
printf(" Here is your product");
printf("\n");
NSLog(@"a * b =%i", c);
char userinput ;
char yesvari = "yes" ;
char novari = "no";
printf("\n");
printf("\n");
printf("Would you like to do another calculation?");
scanf("%i", &userinput);
if (userinput == yesvari) {
NSLog(@" okay cool");
}
if (userinput == novari) {
NSLog(@"okay bye");
}
return 0; }
請告訴我們你有什麼期待,然後什麼洙發生 –