调试后我收到错误

调试后我收到错误

本文介绍了调试后我收到错误,我可以知道如何修复错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! #includestdio.h #includestdafx.h #includestdlib.h #include string.h 双PulauPinangCalculation(双水消费); 双倍JohorCalculation(双水消费) ; 双SelangorCalculation(双水消费); 双LabuanCalculation(双水消费); 双NegeriSembilanCalculation(双水消费); double MelakaCalculation(double waterConsumption); double KedahCalculation(double waterConsumption); double KelantanCalculation(double waterConsumption); double PerakCalculation(双水消费); 双重登嘉楼计算(双水消费); 双倍PahangCalculation(双水消费); 双倍PerlisCalculation(双水消费) ; 双Sarawak1Calculation(双水消费); 双Sarawak2Calculati on(double waterConsumption); 双Sarawak3Calculation(双水消费); 双SabahCalculation(双水消费); int main() { double waterConsumption = 0; int state = 1; while(state!= 0){ printf(由姓名和ID编写:45678 \ n); printf(分类:4SPG1 \ n); printf(这个程序为你计算每月水费。\ n); printf(马来西亚国家\ n); printf(1。 Johor \\\); printf(2.Kedah \ n); printf(3.Kelantan \ n); printf(4.Labuan \ n); printf(5.Malaka \ n); printf(6。 Negeri Sembilan \ n); printf(7.Phanghang \ n); printf(8.Perak \ n); printf(9.Perlis\ n); printf(10.Pulau Pinang \ n); printf( 11. Sabah \ n; printf(12.砂拉越1(古晋,诗巫,Sri Aman,美里,林邦,Sarikei,Kapit)\ n); printf(13。沙捞越2(民都鲁)\ n); printf(14.砂拉越3(沙捞越其他地区)\ n); printf(15.雪兰莪/吉隆坡/ Putrajaya \ n); printf(16. Terengganu \ n); printf(\ n请选择你的州或输入0退出:); while(!scanf_s(%d,& state)){ printf(必须是数字:); getchar(); } 开关(州){ 案例1: printf( 选择状态:Johor \ n); 执行{ printf(请输入本月用水量(以m ^ 3为单位):) ; while(!scanf_s(%lf,& waterConsumption)){ printf(必须是数字:); getchar()!='\ n'; } if(waterConsumption< 0){ printf(错!不能为负值!再次输入!\ n); } else if (waterConsumption> = 0){ double result = JohorCalculation(waterConsumption); printf(你需要支付RM%。2f%n,结果) ; printf(这个月。); printf(\ n ----------------- -------------------------------------------------- --- \ n); } } while(waterConsumption< 0); 休息; 案例2: printf(选择状态:Kedah \ n); 执行{ printf(请键入在本月的用水量(以m ^ 3为单位):); while(!scanf_s(%lf,& waterConsumption)){ printf (必须是数字:); getchar()!='\ n'; } if(waterConsumption< ; 0){ printf(错!不能为负值!再次输入! \\ n); } 否则if(waterConsumption> = 0){ double result = KedahCalculation(waterConsumption); printf(你需要支付RM%.2f%n,结果); printf(这个月。); printf(\ n ------------------------------------------- --------------------------- \ n); } } while(waterConsumption< 0); 休息; 案例3: printf(选择状态:吉兰丹\ n); 做{ printf(请输入本月用水量(以m ^ 3为单位):); while(!scanf_s(% lf,& waterConsumption)){ printf(必须是数字:); getchar()!='\ n'; } if(waterConsumption< 0){ printf(错!不能为负值!再次输入!\ n); } 否则if(waterConsumption> = 0){ double result = KelantanCalculation(waterConsumption); printf(你需要支付RM%.2f%n,结果); printf(这个月。); printf( \ ------------------------------------------------ ---------------------- \ n); } } while(waterConsumption< ; 0); 休息; 案例4: printf(Se le状态:Labuan \\\); 做{ printf(请输入本月用水量(以m ^ 3为单位):); while(!scanf_s(%lf,& waterConsumption)){ printf(必须是数字:); getchar()!='\ n'; } if(waterConsumption< 0){ printf(错!不能为负值!再次输入!\ n); } else if (waterConsumption> = 0){ double result = LabuanCalculation(waterConsumption); printf(你需要支付RM%。2f%n,结果) ; printf(这个月。); printf(\ n ----------------- -------------------------------------------------- --- \ n); } } while(waterConsumption< 0); 休息; 案例5: printf(选择状态:Melaka \ n); 执行{ printf(请键入在本月的用水量(以m ^ 3为单位):); while(!scanf_s(%lf,& waterConsumption)){ printf (必须是数字:); getchar()!='\ n'; } if(waterConsumption< ; 0){ printf(错!不能为负值!再次输入!\ n); } else if(waterConsumption> = 0){ double result = MelakaCalculation(waterConsumption); printf(你需要支付RM%.2f%n,结果); printf(这个月。); printf(\ n ----------------------------------------- ----------------------------- \\\); } } while(waterConsumption< 0); 休息; 案例6: printf(选择状态:Negeri Sembilan \ n); do { printf(请输入本月用水量(以m ^ 3为单位):); while(!scanf_s( %lf,& waterConsumption)){ printf(必须是数字:); getchar()!='\ n'; } if(waterConsumption< 0){ printf(错!不能为负值!再次输入!\ n) ; } 否则if(waterConsumption> = 0){ double result = NegeriSembilanCalculation(waterConsumption); printf(你需要支付RM%.2f%n,结果); printf(这个月。); printf( \\\ ----------------------------------------------- ----------------------- \ n); } } while(waterConsumption < 0); 休息; 案例7: printf(Seleted state:Pahang\\\); do { printf(请输入本月用水量(以m ^ 3为单位): ); while(!scanf_s(%lf,& waterConsumption)){ printf(必须是数字:); getchar()!='\ n'; } if(waterConsumption< 0){ printf(错!不能为负值!再次输入!\ n); } else if (waterConsumption> = 0){ 双倍结果= PahangCalculation(waterConsumption); printf(你需要支付RM%。2f%n,结果) ; printf(这个月。); printf(\ n ----------------- -------------------------------------------------- --- \ n); } } while(waterConsumption< 0); 休息; 案例8: printf(选择状态:Perak \ n); 执行{ printf(请键入在本月的用水量(以m ^ 3为单位):); while(!scanf_s(%lf,& waterConsumption)){ printf (必须是数字:); getchar(); } if(waterConsumption< 0){ printf(错!不能为负值!再次输入!\ n); } 否则if(waterConsumption> = 0){ double result = PerakCalculation(waterConsumption); printf(你需要支付RM%.2f%n,结果); printf(这个月。); printf(\ n-- -------------------------------------------------- ------------------ \ n); } } while(waterConsumption< 0); 休息; 案例9: printf(选择状态:Perlis \ n); 做{ printf(请输入本月用水量(以m ^ 3为单位):); while(!scanf_s(% lf,& waterConsumption)){ printf(必须是数字:); getchar()!='\ n'; } if(waterConsumption< 0){ printf(错!不能为负值!再次输入!\ n); } else if(waterConsumption> = 0){ double result = PerlisCalculation(waterConsumption); printf(你需要支付RM%.2f%n,结果); printf(这个月。); printf( \ ------------------------------------------------ ---------------------- \ n); } } while(waterConsumption< ; 0); 休息; 案例10: printf(Selet ed州:Pulau Pinang \\\); do { printf(请输入本月用水量(以m ^ 3为单位):) ; while(!scanf_s(%lf,& waterConsumption)){ printf(必须是数字:); getchar()!='\ n'; } if(waterConsumption< 0){ printf(错!不能为负值!再次输入!\ n); } else if (waterConsumption> = 0){ 双重结果= PulauPinangCalculation(waterConsumption); printf(你需要支付RM%。2f%n,结果) ; printf(这个月。); printf(\ n ----------------- -------------------------------------------------- --- \ n); } } while(waterConsumption< 0); 休息; 案例11: printf(选择状态:Sabah \ n); 执行{ printf(请键入在本月的用水量(以m ^ 3为单位):); while(!scanf_s(%lf,& waterConsumption)){ printf (必须是数字:); getchar()!='\ n'; } if(waterConsumption< ; 0){ printf(错!不能为负值!键入再次!\ n); } 否则if(waterConsumption> = 0){ double result = SabahCalculation(waterConsumption) ; printf(你需要支付RM%。2f%n,结果); printf(这个月。); printf(\ n ---------------------------------------- ------------------------------ \ n); } } while(waterConsumption< 0); 休息; 案例12: printf(砂拉越1(古晋,诗巫,Sri Aman,美里,林邦,Sarikei) ,Kapit)\ n); 做{ printf(请输入本月用水量(以m ^ 3为单位):); printf(必须是数字:); getchar()!='\ n'; } if(waterConsumption< 0){ printf(错!不能是负值!再次输入!\ n); } 否则if(waterConsumption> = 0){ double result = Sarawak1Calculation(waterConsumption); printf(你需要支付RM%.2f%n,结果); printf(这个月。 ); printf(\ n ---------------------------------- ------------------------------------ \\\); } } while(waterConsumption< 0); break; 案例13: printf(砂拉越2(民都鲁)\ n); do { printf (请输入本月用水量(以m ^ 3为单位):); while(!scanf_s(%lf,& waterConsumption)){ printf(必须是数字:); getchar()!='\ n'; } if(waterConsumption< 0){ printf(错!不能为负值!再次输入!\ n); } else if (waterConsumption> = 0){ double result = Sarawak2Calculation(waterConsumption); printf(你需要支付RM%。2f%n,结果) ; printf(这个月。); printf(\ n ----------------- -------------------------------------------------- --- \ n); } } while(waterConsumption< 0); 休息; 案例14: printf(沙捞越3(沙捞越的其他地区)\ n); do { printf (请输入本月用水量(以m ^ 3为单位):); while(!scanf_s(%lf,& waterConsumption)){ printf(必须是数字:); getchar()!='\ n'; } if(waterConsumption< 0){ printf(错!不能为负值e!再次输入!\ n); } else if(waterConsumption> = 0){ double result = Sarawak3Calculation(waterConsumption); printf(你需要支付RM%.2f%n,结果); printf(这个月。); printf(\ n ------------------------------------ ---------------------------------- \ n); } } while(waterConsumption< 0); 休息; 案例15: printf(Seleted state:Selangor / Kuala Lumpur / Putrajaya \ n); 做{ printf(请输入本月用水量(以m ^ 3为单位):); while( !scanf_s(%lf,& waterConsumption)){ printf(必须是数字:); getchar()!='\ n '; } if(waterConsumption< 0){ printf(错!不能为负值!再次输入! \\ n); } 否则if(waterConsumption> = 0){ double result = SelangorCalculation(waterConsumption); printf(你需要支付RM%.2f%n,结果); printf(这个月。); printf(\ n ------------------------------------------- --------------------------- \ n); } } while(waterConsumption< 0); break; case 16: printf(Seleted state:Terengganu \ n); do { printf(请输入耗水量这个月(以m ^ 3为单位):); while(!scanf_s(%lf,& waterConsumption)){ printf(必须是一个数字:); getchar()!='\ n'; } if(waterConsumption< 0){ printf(错!不能为负值!再次输入!\ n); } else if (waterConsumption> = 0){ double result = TerengganuCalculation(waterConsumption); printf(你需要支付RM%。2f%n,结果) ; printf(这个月。); printf(\ n ----------------- -------------------------------------------------- --- \ n); } } while(waterConsumption< 0); 休息; 案例0: 休息; 默认: printf(\ nInvalid Input! !\ n); } } printf(感谢您使用我的程序。\ n); 返回0; } //槟城 双PulauPinangCalculation(双水消费){ double total = 0; double balanceLitre = 0; double band1 = 0.22 * 20; doub le band2 = 0.46 * 15; double band3 = 0.68 * 20; double band4 = 1.17 * 140; double band5 = 0.48 * 5; if(waterConsumption> = 0&& waterConsumption< = 20){ total = waterConsumption * 0.22; if(total< 2.5){ total = 2.5; balanceLitre = waterConsumption - 20; balanceLitre * = 0.46; total = band1 + balanceLitre; if(waterConsumption> 35){ balanceLitre = waterConsumption - 35; balanceLitre * = 0.48; total = band1 + band2 + balanceLitre; } } else if(waterConsumption> 40&& waterConsumption< = 60){ balanceLitre = waterConsumption - 40 ; balanceLitre * = 0.68; total = band1 + band2 + band5 + balanceLitre; } else if(waterConsumption>&&waterTersumption< = 200){ balanceLitre = waterConsumption - 60; balanceLit re * = 1.17; total = band1 + band2 + band5 + band3 + balanceLitre; } else if(waterConsumption> 200){ balanceLitre = waterConsumption - 200; balanceLitre * = 1.30; total = band1 + band2 + band5 + band3 + band4 + balanceLitre; } 总回报; } //柔佛 double JohorCalculation(double waterConsumption){ double total = 0; double balanceLitre = 0; double band1 = 0.80 * 20; double band2 = 2.00 * 15; if(waterConsumption> = 0&& waterConsumption< = 20){ total = waterConsumption * 0.8; if(total< 7){ total = 7; } } 否则if(waterConsumption> 20&& waterConsumption< = 35){ balanceLitre = waterConsumption - 20; balanceLitre * = 2.00; total = band1 + balanceLitre; } else if(waterConsumption> 35){ balanceLitre = waterConsump - 35; balanceLitre * = 3.00; 总计= band1 + band2 + balanceLitre; } 返回总额; } //雪兰莪/吉隆坡/普特拉贾亚 双重雪兰莪计算(双水消费){ double total = 0; double balanceLitre = 0; double band1 = 0.57 * 20; double band2 = 1.03 * 15; if(waterConsumption> = 0&& waterConsumption< = 20){ total = waterConsumption * 0.57; if(total< 6){ total = 6; $ b $} b $ b b balanceLitre = waterConsumption - 20; balanceLitre * = 1.03; total = band1 + balanceLitre; } 否则if(waterConsumption> 35){ balanceLitre = waterConsumption - 35; balanceLitre * = 2.00; total = band1 + band2 + balanceLitre; } 返回总额; } // Labuan double LabuanCalculation(double waterConsumption){ double total = 0; double balanceLitre = 0; double band1 = 0.70 * 20; double band2 = 1.20 * 15; if(waterConsumption> ; = 0&& waterConsumption< = 20){ total = waterCo nsumption * 0.70; if(total< 7){ 总计= 7; } } 否则if(waterConsumption> 20& & waterConsumption< = 35){ balanceLitre = waterConsumption - 20; balanceLitre * = 1.20; total = band1 + balanceLitre; } 否则if(waterConsumption> 35){ balanceLitre = waterConsumption - 35; balanceLitre * = 1.70; 总计= band1 + band2 + balanceLitre; } 返回总数; } // Negeri Sembilan 双倍NegeriSembilanCalculation(双水消费){ double总计= 0; double balanceLitre = 0; double band1 = 0.55 * 20; double band2 = 0.85 * 15; if(waterConsumption> = 0&& waterConsumption< = 20){ total = waterConsumption * 0.55; 如果(总计 总计= 5; 如果(waterConsumption> 20&& waterConsumption< = 35){ balanceLitre = waterConsumption - 20; balanceLitre * = 0.85; total = band1 + balanceLitre; } 否则if(waterConsumption> 35){ balanceLitre = waterConsumption - 35; balanceLitre * = 1.40; 总计= band1 + band2 + balanceLitre; } 返回总额; } //马六甲 双MelakaCalculation(双水消费){ double total = 0 ; double balanceLitre = 0; double band1 = 0.70 * 20; double band2 = 1.15 * 15; if(waterConsumption> = 0&& waterConsumption< = 20){ total = waterConsumption * 0.70; 如果(总计 总计= 7; } } 否则if(waterConsumption > 20&& waterConsumption< = 35){ balanceLitre = waterConsumption - 20; balanceLitre * = 1.15; total = band1 + balanceLitre; } else if(waterConsumption> 35){ balanceLitre = waterConsumption - 35; balanceLitre * = 1.75; total = band1 + band2 + balanceLitre; } 返回总额; } // Kedah double KedahCalculation(double waterConsumption){ double total = 0; double balanceLitre = 0; double band1 = 0.50 * 20; double band2 = 0.90 * 15; if(waterConsumption> = 0&& waterConsumption< = 20){ total = waterConsumption * 0.50; if(total< 6){ total = 6; } } 否则if(waterConsumption> 20&& waterConsumption< = 35){ balanceLitre = waterConsumption - 20; balanceLitre * = 0.90; 总计= band1 + balanceLitre; } 否则(waterConsumption> 35){ balanceLitre = waterConsumption - 35; balanceLitre * = 1.30; total = band1 + band2 + balanceLitre; } 返回总数; } //吉兰丹 双吉兰丹计算(双水消费){ 总计双倍= 0; double balanceLitre = 0; double band1 = 0.45 * 20; double band2 = 0.97 * 15; if(waterConsumption> = 0&& waterConsumption< = 20){ total = waterConsumption * 0.45; if(total< 4.5){ total = 4.5; $ b $} b $ b b balanceLitre = waterConsumption - 20; balanceLitre * = 0.97; total = band1 + balanceLitre; } else if(waterConsumption> 35){ balanceLitre = waterConsumption - 35; balanceLitre * = 1.42; total = band1 + band2 + balanceLitre; } 返回总额; } //霹雳 双PerakCalculation(双水消费){ 总计= 0; double balanceLitre = 0; double band1 = 0.30 * 10; double band2 = 0.70 * 10; if(waterConsumption> ; = 0&& waterConsumption< = 10){ total = water消耗* 0.30; if(total< 3){ 总计= 3; } } 否则if(waterConsumption> 10& & waterConsumption< = 20){ balanceLitre = waterConsumption - 10; balanceLitre * = 0.70; total = band1 + balanceLitre; } if if(waterConsumption> 20){ balanceLitre = waterConsumption - 20; balanceLitre * = 1.00; total = band1 + band2 + balanceLitre; } 返回总数; } //登嘉楼 双倍登嘉楼计算(双水消费){ 总计双倍= 0; double balanceLitre = 0; double band1 = 0.42 * 20; double band2 = 0.65 * 20; double band3 = 0.90 * 20; if(waterConsumption> = 0&& waterConsumption< = 20){ total = waterConsumption * 0.42; if(total< 4){ 总计= 4; } } 否则if(waterConsumption> 20&& waterConsumption< = 40){ balanceLitre = waterConsumption - 20; balanceLitre * = 0.65; total = band1 + balanceLitre; } else if(waterConsumption> 40&& waterConsumption< = 60){ balanceLitre = waterConsumption - 40; balanceLitre * = 0.90; total = band1 + band2 + balanceLitre; } 否则if(waterConsumption> 60){ balanceLitre = waterConsumption - 60; balanceLitre * = 1.00; 总= band1 + band2 + band3 + balanceLitre; } 返回总额; } //彭亨 双倍PahangCalculation(双水消费){ 总计= 0; double balanceLitre = 0; double band1 = 0.37 * 18; double band2 = 0.79 * 27; if( waterConsumption> = 0&& waterConsumption& lt; = 18){ total = waterConsumption * 0.37; if(total< 3){ 总计= 3; } } 否则if(waterConsumption> 18& & waterConsumption< = 45){ balanceLitre = waterConsumption - 18; balanceLitre * = 0.79; total = band1 + balanceLitre; } 否则if(waterConsumption> 45){ balanceLitre = waterConsumption - 45; balanceLitre * = 0.99; total = band1 + band2 + balanceLitre; } 返回总数; } // Perlis 双倍PerlisCalculation(双水消费){ 总计双倍= 0; double balanceLitre = 0; double band1 = 0.40 * 15; double band2 = 0.70 * 25; if(waterConsumption> = 0&& waterConsumption< = 15){ total = waterConsumption * 0.40; if(总计< 4){ 总计= 4; } } else if(waterConsumption> 15&& waterConsumption< = 40){ balanceLitre = waterConsumption - 15; balanceLitre * = 0.70; total = band1 + balanceLitre; } 否则if(waterConsumption> 40){ balanceLitre = waterConsumption - 40; balanceLitre * = 1.10; 总计= band1 + band2 + balanceLitre; } 返回总额; } //砂拉越1 双重砂拉越1计算(双水消费){ 总计双倍= 0; double balanceLitre = 0; double band1 = 0.48 * 15; double band2 = 0.72 * 35; if(waterConsumption> = 0&& waterConsumption< = 15){ total = waterConsumption * 0.48; 如果(总计 总计= 4.4; } } 否则如果( waterConsumption> 15& waterConsumption< = 50){ balanc eLitre = waterConsumption - 15; \t\tbalanceLitre *= 0.72; \t\ttotal = band1 + balanceLitre; \t} \telse if (waterConsumption > 50) { \t\tbalanceLitre = waterConsumption - 50; \t\tbalanceLitre *= 0.76; \t\ttotal = band1 + band2 + balanceLitre; \t} \treturn total; } //Sarawak 2 double Sarawak2Calculation(double waterConsumption) { \tdouble total = 0; \tdouble balanceLitre = 0; \tdouble band1 = 6.60; \tdouble band2 = 0.61 * 31; \tif (waterConsumption >= 0 && waterConsumption <= 14) { \t\ttotal = 6.6; \t} \telse if (waterConsumption >14 && waterConsumption <= 45) { \t\tbalanceLitre = waterConsumption - 14; \t\tbalanceLitre *= 0.61; \t\ttotal = band1 + balanceLitre; \t} \telse if (waterConsumption > 45) { \t\tbalanceLitre = waterConsumption - 45; \t\tbalanceLitre *= 0.66; \t\ttotal = band1 + band2 + balanceLi tre; \t} \treturn total; } //Sarawak 3 double Sarawak3Calculation(double waterConsumption) { \tdouble total = 0; \tdouble balanceLitre = 0; \tdouble band1 = 0.44 * 15; \tdouble band2 = 0.65 * 35; \tif (waterConsumption >= 0 && waterConsumption <= 15) { \t\ttotal = waterConsumption * 0.44; \t\tif (total < 4) { \t\t\ttotal = 4; \t\t} \t} \telse if (waterConsumption >15 && waterConsumption <= 50) { \t\tbalanceLitre = waterConsumption - 15; \t\tbalanceLitre *= 0.65; \t\ttotal = band1 + balanceLitre; \t} \telse if (waterConsumption > 50) { \t\tbalanceLitre = waterConsumption - 50; \t\tbalanceLitre *= 0.69; \t\ttotal = band1 + band2 + balanceLitre; \t} \treturn total; } //Sabah double SabahCalculation(double waterConsumption) { \tdouble total = 0; \tdouble balanceLitre = 0; \tdouble band1 = 0.30 * 10; \tdouble band2 = 0.60 * 10; \tdouble band3 = 1.10 * 15; \tdouble band4 = 1.30 * 25; \tif (waterConsumption &g t;= 0 && waterConsumption <= 10) { \t\ttotal = waterConsumption * 0.30; \t\tif (total < 3) { \t\t\ttotal = 3; \t\t} \t} \telse if (waterConsumption >10 && waterConsumption <= 20) { \t\tbalanceLitre = waterConsumption - 10; \t\tbalanceLitre *= 0.60; \t\ttotal = band1 + balanceLitre; \t} \telse if (waterConsumption > 20 && waterConsumption <= 35) { \t\tbalanceLitre = waterConsumption - 20; \t\tbalanceLitre *= 1.10; \t\ttotal = band1 + band2 + balanceLitre; \t} \telse if (waterConsumption > 35 && waterConsumption <= 60) { \t\tbalanceLitre = waterConsumption - 35; \t\tbalanceLitre *= 1.30; \t\ttotal = band1 + band2 + band3 + balanceLitre; \t} \telse if (waterConsumption > 60) { \t\tbalanceLitre = waterConsumptio n - 60; \t\tbalanceLitre *= 1.80; \t\ttotal = band1 + band2 + band3 + band4 + balanceLitre; \t} \treturn total; } What I have tried: Step1 Error Msg C4700 uninitialized local variable ’state’ used C4473 ’printf’: not enough arguments passed format string I’m using VB 2015 C Language Step2 update, after I change from int state; to int state = 1; that big boss advice it’s able to debug but then after I key in the number and I’m getting another error which is \"Debug Assertion Failed\" Expression: (\"’n’ format specifier disabled\", 0)#include "stdio.h"#include "stdafx.h"#include "stdlib.h"#include "string.h"double PulauPinangCalculation(double waterConsumption);double JohorCalculation(double waterConsumption);double SelangorCalculation(double waterConsumption);double LabuanCalculation(double waterConsumption);double NegeriSembilanCalculation(double waterConsumption);double MelakaCalculation(double waterConsumption);double KedahCalculation(double waterConsumption);double KelantanCalculation(double waterConsumption);double PerakCalculation(double waterConsumption);double TerengganuCalculation(double waterConsumption);double PahangCalculation(double waterConsumption);double PerlisCalculation(double waterConsumption);double Sarawak1Calculation(double waterConsumption);double Sarawak2Calculation(double waterConsumption);double Sarawak3Calculation(double waterConsumption);double SabahCalculation(double waterConsumption);int main(){double waterConsumption = 0;int state = 1;while (state != 0) {printf("Prepared by Name and ID: 45678\n");printf("Class: 4SPG1\n");printf("This program calculates the monthly water bill for you.\n");printf("States in Malaysia\n");printf("1. Johor\n");printf("2. Kedah\n");printf("3. Kelantan\n");printf("4. Labuan\n");printf("5. Melaka\n");printf("6. Negeri Sembilan\n");printf("7. Pahang\n");printf("8. Perak\n");printf("9. Perlis\n");printf("10. Pulau Pinang\n");printf("11. Sabah\n");printf("12. Sarawak 1(Kuching, Sibu, Sri Aman, Miri, Limbang, Sarikei, Kapit)\n");printf("13. Sarawak 2(Bintulu)\n");printf("14. Sarawak 3(Other Parts of Sarawak)\n");printf("15. Selangor / Kuala Lumpur / Putrajaya\n");printf("16. Terengganu\n");printf("\nPlease select your state or enter 0 to exit: ");while (!scanf_s("%d", &state)) {printf("Must be a number: ");getchar();}switch (state) {case 1:printf("Seleted state: Johor\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = JohorCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 2:printf("Seleted state: Kedah\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = KedahCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 3:printf("Seleted state: Kelantan\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = KelantanCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 4:printf("Seleted state: Labuan\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = LabuanCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 5:printf("Seleted state: Melaka\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = MelakaCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 6:printf("Seleted state: Negeri Sembilan\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = NegeriSembilanCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 7:printf("Seleted state: Pahang\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = PahangCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 8:printf("Seleted state: Perak\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar();}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = PerakCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 9:printf("Seleted state: Perlis\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = PerlisCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 10:printf("Seleted state: Pulau Pinang\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = PulauPinangCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 11:printf("Seleted state: Sabah\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = SabahCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 12:printf("Sarawak 1(Kuching, Sibu, Sri Aman, Miri, Limbang, Sarikei, Kapit)\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = Sarawak1Calculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 13:printf("Sarawak 2(Bintulu)\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = Sarawak2Calculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 14:printf("Sarawak 3(Other Parts of Sarawak)\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = Sarawak3Calculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 15:printf("Seleted state: Selangor / Kuala Lumpur / Putrajaya\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = SelangorCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 16:printf("Seleted state: Terengganu\n");do {printf("Please key in the water consumption for this month (in m^3): ");while (!scanf_s("%lf", &waterConsumption)) {printf("Must be a number: ");getchar() != '\n';}if (waterConsumption < 0) {printf("Wrong! Cannot be negative value! Key in again!\n");}else if (waterConsumption >= 0) {double result = TerengganuCalculation(waterConsumption);printf("You need to pay for RM %.2f%n", result);printf(" for this month.");printf("\n----------------------------------------------------------------------\n");}} while (waterConsumption < 0);break;case 0:break;default:printf("\nInvalid Input!!\n");}}printf("Thanks for using my program.\n");return 0;}// Penangdouble PulauPinangCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.22 * 20;double band2 = 0.46 * 15;double band3 = 0.68 * 20;double band4 = 1.17 * 140;double band5 = 0.48 * 5;if (waterConsumption >= 0 && waterConsumption <= 20) {total = waterConsumption * 0.22;if (total < 2.5) {total = 2.5;}}else if (waterConsumption >20 && waterConsumption <= 40) {balanceLitre = waterConsumption - 20;balanceLitre *= 0.46;total = band1 + balanceLitre;if (waterConsumption > 35) {balanceLitre = waterConsumption - 35;balanceLitre *= 0.48;total = band1 + band2 + balanceLitre;}}else if (waterConsumption > 40 && waterConsumption <= 60) {balanceLitre = waterConsumption - 40;balanceLitre *= 0.68;total = band1 + band2 + band5 + balanceLitre;}else if (waterConsumption > 60 && waterConsumption <= 200) {balanceLitre = waterConsumption - 60;balanceLitre *= 1.17;total = band1 + band2 + band5 + band3 + balanceLitre;}else if (waterConsumption > 200) {balanceLitre = waterConsumption - 200;balanceLitre *= 1.30;total = band1 + band2 + band5 + band3 + band4 + balanceLitre;}return total;}//Johordouble JohorCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.80 * 20;double band2 = 2.00 * 15;if (waterConsumption >= 0 && waterConsumption <= 20) {total = waterConsumption * 0.8;if (total < 7) {total = 7;}}else if (waterConsumption >20 && waterConsumption <= 35) {balanceLitre = waterConsumption - 20;balanceLitre *= 2.00;total = band1 + balanceLitre;}else if (waterConsumption > 35) {balanceLitre = waterConsumption - 35;balanceLitre *= 3.00;total = band1 + band2 + balanceLitre;}return total;}//Selangor/KL/Putrajayadouble SelangorCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.57 * 20;double band2 = 1.03 * 15;if (waterConsumption >= 0 && waterConsumption <= 20) {total = waterConsumption * 0.57;if (total < 6) {total = 6;}}else if (waterConsumption >20 && waterConsumption <= 35) {balanceLitre = waterConsumption - 20;balanceLitre *= 1.03;total = band1 + balanceLitre;}else if (waterConsumption > 35) {balanceLitre = waterConsumption - 35;balanceLitre *= 2.00;total = band1 + band2 + balanceLitre;}return total;}//Labuandouble LabuanCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.70 * 20;double band2 = 1.20 * 15;if (waterConsumption >= 0 && waterConsumption <= 20) {total = waterConsumption * 0.70;if (total < 7) {total = 7;}}else if (waterConsumption >20 && waterConsumption <= 35) {balanceLitre = waterConsumption - 20;balanceLitre *= 1.20;total = band1 + balanceLitre;}else if (waterConsumption > 35) {balanceLitre = waterConsumption - 35;balanceLitre *= 1.70;total = band1 + band2 + balanceLitre;}return total;}//Negeri Sembilandouble NegeriSembilanCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.55 * 20;double band2 = 0.85 * 15;if (waterConsumption >= 0 && waterConsumption <= 20) {total = waterConsumption * 0.55;if (total < 5) {total = 5;}}else if (waterConsumption >20 && waterConsumption <= 35) {balanceLitre = waterConsumption - 20;balanceLitre *= 0.85;total = band1 + balanceLitre;}else if (waterConsumption > 35) {balanceLitre = waterConsumption - 35;balanceLitre *= 1.40;total = band1 + band2 + balanceLitre;}return total;}//Melakadouble MelakaCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.70 * 20;double band2 = 1.15 * 15;if (waterConsumption >= 0 && waterConsumption <= 20) {total = waterConsumption * 0.70;if (total < 7) {total = 7;}}else if (waterConsumption >20 && waterConsumption <= 35) {balanceLitre = waterConsumption - 20;balanceLitre *= 1.15;total = band1 + balanceLitre;}else if (waterConsumption > 35) {balanceLitre = waterConsumption - 35;balanceLitre *= 1.75;total = band1 + band2 + balanceLitre;}return total;}//Kedahdouble KedahCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.50 * 20;double band2 = 0.90 * 15;if (waterConsumption >= 0 && waterConsumption <= 20) {total = waterConsumption * 0.50;if (total < 6) {total = 6;}}else if (waterConsumption >20 && waterConsumption <= 35) {balanceLitre = waterConsumption - 20;balanceLitre *= 0.90;total = band1 + balanceLitre;}else if (waterConsumption > 35) {balanceLitre = waterConsumption - 35;balanceLitre *= 1.30;total = band1 + band2 + balanceLitre;}return total;}//Kelantandouble KelantanCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.45 * 20;double band2 = 0.97 * 15;if (waterConsumption >= 0 && waterConsumption <= 20) {total = waterConsumption * 0.45;if (total < 4.5) {total = 4.5;}}else if (waterConsumption >20 && waterConsumption <= 35) {balanceLitre = waterConsumption - 20;balanceLitre *= 0.97;total = band1 + balanceLitre;}else if (waterConsumption > 35) {balanceLitre = waterConsumption - 35;balanceLitre *= 1.42;total = band1 + band2 + balanceLitre;}return total;}//Perakdouble PerakCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.30 * 10;double band2 = 0.70 * 10;if (waterConsumption >= 0 && waterConsumption <= 10) {total = waterConsumption * 0.30;if (total < 3) {total = 3;}}else if (waterConsumption > 10 && waterConsumption <= 20) {balanceLitre = waterConsumption - 10;balanceLitre *= 0.70;total = band1 + balanceLitre;}else if (waterConsumption > 20) {balanceLitre = waterConsumption - 20;balanceLitre *= 1.00;total = band1 + band2 + balanceLitre;}return total;}// Terengganudouble TerengganuCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.42 * 20;double band2 = 0.65 * 20;double band3 = 0.90 * 20;if (waterConsumption >= 0 && waterConsumption <= 20) {total = waterConsumption * 0.42;if (total < 4) {total = 4;}}else if (waterConsumption >20 && waterConsumption <= 40) {balanceLitre = waterConsumption - 20;balanceLitre *= 0.65;total = band1 + balanceLitre;}else if (waterConsumption > 40 && waterConsumption <= 60) {balanceLitre = waterConsumption - 40;balanceLitre *= 0.90;total = band1 + band2 + balanceLitre;}else if (waterConsumption > 60) {balanceLitre = waterConsumption - 60;balanceLitre *= 1.00;total = band1 + band2 + band3 + balanceLitre;}return total;}//Pahangdouble PahangCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.37 * 18;double band2 = 0.79 * 27;if (waterConsumption >= 0 && waterConsumption <= 18) {total = waterConsumption * 0.37;if (total < 3) {total = 3;}}else if (waterConsumption >18 && waterConsumption <= 45) {balanceLitre = waterConsumption - 18;balanceLitre *= 0.79;total = band1 + balanceLitre;}else if (waterConsumption > 45) {balanceLitre = waterConsumption - 45;balanceLitre *= 0.99;total = band1 + band2 + balanceLitre;}return total;}//Perlisdouble PerlisCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.40 * 15;double band2 = 0.70 * 25;if (waterConsumption >= 0 && waterConsumption <= 15) {total = waterConsumption * 0.40;if (total < 4) {total = 4;}}else if (waterConsumption >15 && waterConsumption <= 40) {balanceLitre = waterConsumption - 15;balanceLitre *= 0.70;total = band1 + balanceLitre;}else if (waterConsumption > 40) {balanceLitre = waterConsumption - 40;balanceLitre *= 1.10;total = band1 + band2 + balanceLitre;}return total;}//Sarawak 1double Sarawak1Calculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.48 * 15;double band2 = 0.72 * 35;if (waterConsumption >= 0 && waterConsumption <= 15) {total = waterConsumption * 0.48;if (total < 4.4) {total = 4.4;}}else if (waterConsumption >15 && waterConsumption <= 50) {balanceLitre = waterConsumption - 15;balanceLitre *= 0.72;total = band1 + balanceLitre;}else if (waterConsumption > 50) {balanceLitre = waterConsumption - 50;balanceLitre *= 0.76;total = band1 + band2 + balanceLitre;}return total;}//Sarawak 2double Sarawak2Calculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 6.60;double band2 = 0.61 * 31;if (waterConsumption >= 0 && waterConsumption <= 14) {total = 6.6;}else if (waterConsumption >14 && waterConsumption <= 45) {balanceLitre = waterConsumption - 14;balanceLitre *= 0.61;total = band1 + balanceLitre;}else if (waterConsumption > 45) {balanceLitre = waterConsumption - 45;balanceLitre *= 0.66;total = band1 + band2 + balanceLitre;}return total;}//Sarawak 3double Sarawak3Calculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.44 * 15;double band2 = 0.65 * 35;if (waterConsumption >= 0 && waterConsumption <= 15) {total = waterConsumption * 0.44;if (total < 4) {total = 4;}}else if (waterConsumption >15 && waterConsumption <= 50) {balanceLitre = waterConsumption - 15;balanceLitre *= 0.65;total = band1 + balanceLitre;}else if (waterConsumption > 50) {balanceLitre = waterConsumption - 50;balanceLitre *= 0.69;total = band1 + band2 + balanceLitre;}return total;}//Sabahdouble SabahCalculation(double waterConsumption) {double total = 0;double balanceLitre = 0;double band1 = 0.30 * 10;double band2 = 0.60 * 10;double band3 = 1.10 * 15;double band4 = 1.30 * 25;if (waterConsumption >= 0 && waterConsumption <= 10) {total = waterConsumption * 0.30;if (total < 3) {total = 3;}}else if (waterConsumption >10 && waterConsumption <= 20) {balanceLitre = waterConsumption - 10;balanceLitre *= 0.60;total = band1 + balanceLitre;}else if (waterConsumption > 20 && waterConsumption <= 35) {balanceLitre = waterConsumption - 20;balanceLitre *= 1.10;total = band1 + band2 + balanceLitre;}else if (waterConsumption > 35 && waterConsumption <= 60) {balanceLitre = waterConsumption - 35;balanceLitre *= 1.30;total = band1 + band2 + band3 + balanceLitre;}else if (waterConsumption > 60) {balanceLitre = waterConsumption - 60;balanceLitre *= 1.80;total = band1 + band2 + band3 + band4 + balanceLitre;}return total;}What I have tried:Step1Error MsgC4700 uninitialized local variable 'state' usedC4473 'printf': not enough arguments passed format stringI'm using VB 2015 C LanguageStep2update, after I change from int state; to int state = 1; that big boss adviceit's able to debug but then after I key in the number and I'm getting another error which is"Debug Assertion Failed"Expression: ("'n' format specifier disabled", 0)推荐答案nt main(){double waterConsumption = 0;int state;while (state != 0) { // you cannot use this expression because you have not set any value in 'state'.printf("Prepared by Name and ID: 45678\n");No one will fizzle out your messy code. But the first error message means that state need some value before running. It is correct because C doesnt initialize memory. Solution 1:No one will fizzle out your messy code. But the first error message means that state need some value before running. It is correct because C doesnt initialize memory.Solution 1:int state = -1; Solution 2: read your code carefuly to find what is missing in this place. I guess that there isnt a string. Think about using some struct in your code and more constants and functions. LikeSolution 2: read your code carefuly to find what is missing in this place. I guess that there isnt a string.Think about using some struct in your code and more constants and functions. Likestruct City{ char name[30]; float price; int waterConsumption;};void CalculatePrice( struct City *city ); Serious tip: Read Learn C++!!!Richard MacCutchan already explained the first error. The printf problem is caused by specifying two parameters in your string, and then providing only one:Richard MacCutchan already explained the first error.The printf problem is caused by specifying two parameters in your string, and then providing only one:printf("You need to pay for RM %.2f%n", result); 这篇关于调试后我收到错误,我可以知道如何修复错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-12 13:31