當我嘗試運行輸出中有問題的代碼。如何解決這個C代碼?
當輸入s = 1,m = 1時,能輸出太陽能和主電源接觸器。
當兩個輸入均爲0,即S = 0和m = 0,則它給 「沒有功率」。(正確的輸出)
當s = 1時,m = 0時,應該說「有沒有力量「。並能夠得到正確的輸出。
當s = 0時,m = 1,應該說「沒有電力」,而是繼續到太陽能接觸器信息(不是正確的輸出)。
那麼,有什麼可以解決我的問題嗎?一個錯誤的
#include<stdio.h>
#include<stdbool.h>
#define TRUE 1
#define FALSE 0
int main()
{
bool s, m; //input parameters
bool a, b;
bool p, q;
bool t; //output parameters
printf("Enter the value of solar VMD : \n"); //scanning vmd values of solar
scanf("%d", &s);
printf("Enter the value of Mains VMD : \n"); //scanning vmd values of Mains
scanf("%d", &m);
if(s == 1,m == 1)
{
printf("Scan solar contactor : \n"); //scanning solar contactor
scanf("%d", &a);
printf("Scan Mains contactor : \n"); //scanning mains contactor
scanf("%d", &b);
if(a == 1, b == 1) //when solar & mains contactor are close
{
q = FALSE;
p = TRUE;
printf("Solar contactor and Mains contactor: %d %d", p, q);
}
else if(a == 0, b == 1) //when solar contctor is open and mains is closed
{
q = FALSE;
p = TRUE;
printf("Solar contactor and Mains contactor: %d %d", p, q);
}
else if(a == 1, b == 0) //when solar contactor is closed and mains is open
{
q = FALSE;
p = TRUE;
printf("Solar contactor and Mains contactor: %d %d", p, q);
}
else if(a == 0, b == 0) //when both solar and mains are open
{
q = FALSE;
p = TRUE;
printf("Solar contactor and Mains contactor: %d %d", p, q);
}
else
{
printf("Problem with contactors");
}
}
else
{
printf("There is no power");
}
getchar();
getchar();
return 0;
}
您是否可以真正格式化代碼以便讀取它? – 2012-02-19 06:36:46
除了格式化之外,你能否給你的問題一個標題,它實際上告訴我們關於你所問的問題的一些問題? 「如何用C代碼解決這個問題」可能與任何事情有關。 – Bart 2012-02-19 06:41:14