Click here to Skip to main content
15,919,121 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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: "<
Posted
Updated 1-Nov-16 18:54pm

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.
 
Share this answer
 
Comments
Member 12765182 2-Nov-16 0:21am    
Thanks, but it runs a infinite loop
oops. sorry.

sorry - should be:

for( nLcv = 0 ; nLcv < nTimes ; nLcv++ ){
 
Share this answer
 
Comments
Member 12765182 2-Nov-16 1:13am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900