嗯,我編碼這一些功課,我知道它可以更好地修改,並可以使用一些更多的意見,但這一個錯誤正在殺死我......想知道如果它只是我或某事,但你能告訴我,如果錯誤發生在你身上。爲什麼我的閱讀類型爲空?
錯誤:閱讀類型沒有任何數據。
(你可以使用這些投入,現在因爲我沒有錯誤檢查程序) 測試變量:
2345 AA 20 30 40 50 60 10 R(supposed to be entered) but program skip
它是假設採取輸入rea_type但它並繼續跳到其他線路。
下面是代碼:
const float deposit = 1500.00;
const unsigned multiplier =1;
const float rate_One = 6.350;
const float rate_Two = 14.520;
unsigned bill_Cycle = 0,
no_Days = 0;
float bi_Exch_Rate = 0,
ba_Exch_Rate = 0;
float cur_Read=0,
prev_Read=0,
cur_Usage=0,
cur_Peri_Charg=0;
char c_Digit[20],
premis_numb[20];
char rea_type;
/**Information to be collected from the user**/
system("cls");
printf("\nPlease enter the customer digits: ");
scanf("%s",&c_Digit);
printf("\nPlease enter Premise Number:");
scanf("%s",&premis_numb);
printf("\nPlease enter the Billing Cycle: ");
scanf("%d",&bill_Cycle);
printf("\nPlease enter the No. of Days: ");
scanf("%d",&no_Days);
printf("\nPlease enter the Billing Exchange Rate: ");
scanf("%f",&bi_Exch_Rate);
printf("\nPlease enter the Base Exchange Rate: ");
scanf("%f",&ba_Exch_Rate);
printf("\nPlease enter the Current Reading: ");
scanf("%f",&cur_Read);
printf("\nPlease enter the Previous Reading: ");
scanf("%f",&prev_Read);
printf("What is the Reading Type: ");
scanf("%c",&rea_type);
cur_Usage = cur_Read-prev_Read;
if (cur_Usage<100)
{
cur_Peri_Charg = cur_Usage*rate_One;
}
else
{
cur_Peri_Charg = (((cur_Usage-100) * rate_One)+(cur_Usage*rate_Two));
}
strcat(premis_numb,c_Digit);/**Joins the Premis Number and the Customer digits together**/
/**Information to be displayed showing user all input and calculations.**/
system("cls");
printf("\tStored constants for calculation of customer bill\n");
printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf(" Customer Number:%s",premis_numb);
printf(" Current Usage:%.2f \n",cur_Usage);
printf("\n");
printf(" Billing Cycle:%d\t\t No of Days:%d\n",bill_Cycle,no_Days);
printf("\n");
printf(" Billing Exchange Rate:%.2f Base Exchange Rate:%.2f\n",bi_Exch_Rate,ba_Exch_Rate);
printf("\n");
printf(" Deposit:%.2f\t\t Multiplier:%d\n",deposit,multiplier);
printf("\n");
printf(" Rate 1:%.3f\t\t Rate 2:%.3f\n",rate_One,rate_Two);
printf("\n");
printf(" Current Reading:%.2f\t Previous Reading:%.2f\n",cur_Read,prev_Read);
printf("\n");
printf(" Current Usage Reading:%.2f Reading Type:%c\n",cur_Peri_Charg,rea_type);
printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
由於'c_Digit'和'premis_numb'都是數組,所以在這種情況下無關緊要。 –
@Paul R我把它留作字符,因爲它只需要一個字母或者假設只接受一個字母......並且我對premis和c_digit進行了更改,謝謝 – user2861799
即使您只需要一個字符串字符,否則很容易得到一個空白字符而不是預期的字符。之後你可以解析字符串,並刪除任何空白或其他不需要的字符,並只提取你需要的字符。 –