English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

程式目標:使用一個主程式
 
在3種選擇中 執行指定內容

1. 選擇 1.大到小 2.小到大 選擇完輸入5個數比較

2. 輸入邊長 求正方形體積

3. 1.坪數與平方公尺轉換 2.平方公尺與坪數轉換

以下是我所打的程式內容 但是執行有錯

不知道問題在哪邊 希望能幫我解答

3q

#include
using namespace std;
//體積===========================
double ar(double z){
z*=z;
z=z*z*z;
return z;
}
//坪轉平方公尺=====================
double change(double v){
double g;
g=v*3.31;
return g;
}
//平方公尺轉坪=====================
double change2(double m){
double h;
h=m*0.3;
return h;
}
int main()
{
int f,g,h,i,k,z;
int a,b,c,d,e;
double bb,cc;
cout<<"1.輸入5個數排序2.算正方體體積3.坪與平方公尺轉換\n";
loop2:
cin>>k;
switch(k){
case 1:
cout<<"1.由大到小 2.由小到大\n";
loop3:
cin>>a;
switch(a){
case 1:
cout<<"請輸入五個數\n";
const int e=5;
int x[e];
for(int i=0;i cin>>x[i];}
for(int a=0;a for(int b=a+1;b if(x[b]>x[a]){
int c=x[b];
x[b]=x[a];
x[a]=c;
}
}
}
for(int j=0;j cout<<" "< }
}
break;
case 2:
cout<<"請輸入五個數\n";
const int e=5;
int x[e];
for(int i=0;i cin>>x[i];}
for(int a=0;a for(int b=a+1;b if(x[b] int c=x[b];
x[b]=x[a];
x[a]=c;
}
}
}
for(int j=0;j cout<<" "< }
}
default:
cout<<"請輸入1~2\n";
goto loop3;

case 2:
cout<<"請輸入邊長\n";
cin>>a;
bb=ar(a);
cout<<"正方體體積="< break;

case 3:
cout<<"坪轉平方公尺:1;平方公尺轉坪:2\n";
loop:
cin>>a;
switch(a){
case 1:
cout<<"請輸入坪數:";
cin>>cc;
bb=change(cc);
cout<<"轉換平方公尺為:"< break;
case 2:
cout<<"請輸入平方公尺:";
cin>>cc;
bb=change2(cc);
cout<<"轉換坪數為:"< break;

default:
cout<<"請輸入1~2\n";
goto loop;
}
break;


default:
cout<<"請輸入1~3\n";
goto loop2;

system("pause");
return 0;
}

2007-01-05 20:23:21 · 1 個解答 · 發問者 AGP 專業USB線材 2 in 電腦與網際網路 程式設計

題目是 C 的程式問題 那2個 不知道怎麼不見了= =
 
我的內容 斜線也都不見了 [\n]

真的不好意思 

2007-01-05 21:48:56 · update #1

題目是C++ C 加加程式問題 那2個加不知道怎麼不見了
 
我的內容 斜線也都不見了 [\n]

真的不好意思 

2007-01-05 21:50:27 · update #2

那能麻煩給我信箱嗎= =?
 
我改過之後還是不行...
 
3q

2007-01-10 18:08:07 · update #3

1 個解答

基本上 兩個 } 的位置錯誤及少了一個 break;(紅色部分)
int main()
{
...
switch(a){
case 1:
cout<<"請輸入五個數n";
const int e=5;
int x[e];
for(int i=0;i cin>>x[i];}
for(int a=0;a for(int b=a+1;b if(x[b]>x[a]){
int c=x[b];
x[b]=x[a];
x[a]=c;
}
}
}
for(int j=0;j cout<<" "< }
// }
break;
case 2:
cout<<"請輸入五個數n";
const int e=5;
int x[e];
for(int i=0;i cin>>x[i];}
for(int a=0;a for(int b=a+1;b if(x[b] int c=x[b];
x[b]=x[a];
x[a]=c;
}
}
}
for(int j=0;j cout<<" "< }
// }
default:
cout<<"請輸入1~2n";
goto loop3;
}
break;
case 2:
cout<<"請輸入邊長n";
...
case 3:
cout<<"坪轉平方公尺:1;平方公尺轉坪:2n";
...
default:
cout<<"請輸入1~3n";
goto loop2;
}
system("pause");
return 0;
}
如果有問題, 請來函討論. 不然, 我可能會錯失你再補充的疑點.

2007-01-10 08:37:25 · answer #1 · answered by JJ 7 · 0 0

fedest.com, questions and answers