想請問為什麼我這樣的程式,會全部輸出fake?
#include<iostream>
using namespace std;
int main (){
char a;
int b[9];
int i = 0,c = 0;
char array[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L','M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'X', 'Y', 'W', 'Z', 'I', 'O'};
cin >> a >> b[9];
while (a != array [i]){
i++;
}
c = (((i+10)-((i+10)%10))/10) + ((i%10)*9) + (b[0]*1) + (b[1]*2) + (b[2]*3) + (b[3]*4) + (b[4]*5) + (b[5]*6) + (b[6]*7) + (b[7]*8) + b[8];
if((c%10) == 0){
cout << "real";
}
else if((c%10) != 0){
cout << "fake";
}
cout << endl;
return 0;
}
我剛發現我看錯題目,但是重新改過的程式仍然全部輸出fake,想請問哪裡出錯?(新手請見諒
#include<iostream>
using namespace std;
int main (){
char a;
int b[9];
int i = 0,c = 0;
char array[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L','M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'X', 'Y', 'W', 'Z', 'I', 'O'};
cin >> a >> b[9];
while (a != array [i]){
i++;
}
c = (((i+10)-((i+10)%10))/10) + ((i%10)*9) + (b[0]*8) + (b[1]*7) + (b[2]*6) + (b[3]*5) + (b[4]*4) + (b[5]*3) + (b[6]*2) + (b[7]*1) + b[8];
if((c%10) == 0){
cout << "real";
}
else if((c%10) != 0){
cout << "fake";
}
cout << endl;
return 0;
}