我是基督徒我目前是C++的初學者,並試圖學習,但我想我已經在我的極限了,我已經嘗試了其他的東西,但我似乎無法讓我的程序工作。這也是我的課程要求之一,我真的很難找出如何解決這個問題。輸入值和If語句
基本上用戶將輸入站點(a,b,c),程序應計算費用,但輸入a,b或c後,程序輸出0.00000,則任何鍵都將自動關閉界面。
下面是代碼的樣本,我想一起工作:
#include<stdio.h>
#include<conio.h>
main()
{
float fee, to, from, a, b, c;
printf("Enter your current station: ");
scanf("%f",&from);
printf("Enter the station you want to go: ");
scanf("%f",&to);
if((to == a && from == b))
a = 10;
b = 15;
fee = to + from;
printf("%f", fee);
if((to == b && from == a))
a = 10;
b = 15;
fee = to + from;
printf("%f", fee);
if((to == c && from == a))
a = 10;
c = 5;
fee = to + from;
printf("%f", fee);
if((to == a && from == c))
a = 10;
c = 5;
fee = to + from;
printf("%f", fee);
if((to == b && from == c))
a = 10;
c = 5;
fee = to + from;
printf("%f", fee);
getch();
}
希望有人可以幫助我,感謝您閱讀我真的很感激。
嗨,謝謝你的回答,但說實話,我真的不太明白你說的話。 你可以給我示例代碼嗎? 再次謝謝你。 – 2013-03-08 12:26:26
那麼,另一個答案給出了有關if語句問題的更多細節。問題在於你將a,b和c作爲變量,但你也試圖將它們看作是簡單的字母a,b和c。當你想把它們稱爲字母時,你需要像這樣引用它們:if((to =='a'&& from =='c')) – 2013-03-08 12:32:39