在哪个函数中我会使用while循环让我的程序运行多个数据。 [英] In which function would I put a while loop to have my program run more than one data.
问题描述
2 //本程序使用函数计算平方的面积。
3
4
5 #include
6使用命名空间std;
7 double getLength();
8 double getLength2();
9 double getArea(double长度,双倍长度2);
10 void displayData(双倍长度,双倍长度2,双倍面积);
11
12 int main()
13 {
14双倍长度,长度2,面积;
15
16 length = getLength();
17 length2 = getLength2();
18 area = getArea(length,length2);
19 displayData(length,length2,area) ;
20
21返回0;
22}
23
24 double getLength()
25 {
26双倍长度;
27
28 cout<< Hola,:)输入广场的第一个长度:<>长度;
30
31返回长度;
32 }
33
34 double getLength2()
35 {
36 double length2;
37
38 cout<<Hola,:)输入广场的第二个长度:<> length2;
40
41返回长度2;
42}
43
44倍getArea(双倍长度,双倍长度2)
45 {
46
47返回长度*长度2;
48
49}
50
51 void displayData(双倍长度,双倍长度2,双倍面积)
52 {
53
54 cout<<恭喜,你想出第一个长度是:<
我是什么尝试过:
2 //本程序使用函数计算平方的面积。
3
4
5 #include
6使用命名空间std;
7 double getLength();
8 double getLength2();
9 double getArea(double length,double length2);
10 void displayData(double length,double length2,double area);
11
12 int main()
13 {
14双倍长度,长度2,面积;
15
16长度= getLength();
17 length2 = getLength2();
18 area = getArea(length,length2);
19 displayData(length,长度2,面积);
20
21返回0;
22}
23
24 double getLength()
25 {
26双倍长度;
27
28 cout<< Hola,:)输入广场的第一个长度:<>长度;
30
31返回长度;
32 }
33
34 double getLength2()
35 {
36 double length2;
37
38 cout<<Hola,:)输入广场的第二个长度:<> length2;
40
41返回长度2;
42}
43
44倍getArea(双倍长度,双倍长度2)
45 {
46
47返回长度*长度2;
48
49}
50
51 void displayData(双倍长度,双倍长度2,双倍面积)
52 {
53
54 cout<<恭喜,你发现第一个长度是:<
2 //This Program utilizes a function to calculate the square's area.
3
4
5 #include
6 using namespace std;
7 double getLength();
8 double getLength2();
9 double getArea(double length, double length2);
10 void displayData(double length, double length2, double area);
11
12 int main()
13 {
14 double length,length2, area;
15
16 length = getLength();
17 length2 = getLength2();
18 area = getArea(length,length2);
19 displayData(length,length2,area);
20
21 return 0;
22 }
23
24 double getLength()
25 {
26 double length;
27
28 cout << " Hola,:) enter the first length of the square: "<>length;
30
31 return length;
32 }
33
34 double getLength2()
35 {
36 double length2;
37
38 cout<<" Hola, :) enter the second length of the square: "<>length2;
40
41 return length2;
42 }
43
44 double getArea(double length, double length2)
45 {
46
47 return length * length2;
48
49 }
50
51 void displayData(double length, double length2, double area)
52 {
53
54 cout<<" Congrats,You figured out that the first length is: "<
What I have tried:
2 //This Program utilizes a function to calculate the square's area.
3
4
5 #include
6 using namespace std;
7 double getLength();
8 double getLength2();
9 double getArea(double length, double length2);
10 void displayData(double length, double length2, double area);
11
12 int main()
13 {
14 double length,length2, area;
15
16 length = getLength();
17 length2 = getLength2();
18 area = getArea(length,length2);
19 displayData(length,length2,area);
20
21 return 0;
22 }
23
24 double getLength()
25 {
26 double length;
27
28 cout << " Hola,:) enter the first length of the square: "<>length;
30
31 return length;
32 }
33
34 double getLength2()
35 {
36 double length2;
37
38 cout<<" Hola, :) enter the second length of the square: "<>length2;
40
41 return length2;
42 }
43
44 double getArea(double length, double length2)
45 {
46
47 return length * length2;
48
49 }
50
51 void displayData(double length, double length2, double area)
52 {
53
54 cout<<" Congrats,You figured out that the first length is: "<
推荐答案
如果我了解你正确地说,你需要在你的主函数中这样的东西:
int main(){
double length,length2,area = 0.0f ;
int nLcv = 0;
int nTimes = 3;
for(nLcv = 0; nLcv < nTimes; n ++){
length = getLength();
length2 = getLength2();
area = getArea(length,length2);
displayData(长度,长度2,面积);
}
返回0;
}
ps注意我为变量声明分配了一个值0.0f。
If I understand you correctly, you want something like this in your main function:
int main() {
double length,length2, area = 0.0f;
int nLcv = 0 ;
int nTimes = 3;
for( nLcv = 0 ; nLcv < nTimes ; n++ ){
length = getLength();
length2 = getLength2();
area = getArea(length,length2);
displayData(length,length2,area);
}
return 0;
}
p.s. note I assigned a value 0.0f to your variables declaration.
oops。对不起。
抱歉 - 应该是:
for(nLcv = 0; nLcv< nTimes; nLcv ++){
oops. sorry.
sorry - should be:
for( nLcv = 0 ; nLcv < nTimes ; nLcv++ ){
这篇关于在哪个函数中我会使用while循环让我的程序运行多个数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!