if...else if...else 判斷式 (一)
運用 if...else if...else 判斷式,比較 x 與 y 的大小關係。


二擇一
if( )
{
}
else
{
}
多擇一
if( )
{
}
else if( )
{
}
else if( )
{
}
else
{
}
多擇多 / 多擇無
if( )
{
}
if( )
{
}
if( )
{
}
if( )
{
}- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int x, y;
- re:
- cout<<"請輸入x: ";
- cin>>x;
- cout<<"請輸入y: ";
- cin>>y;
- if(x>y)
- cout<<"x大於y!"<<endl;
- else if(x<y)
- cout<<"x小於y!"<<endl;
- else
- cout<<"兩數相等!"<<endl;
- cout<<endl;
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |