Question about input

I wrote a program to calculate the hypotenuse of a right triangle with two different methods. I'm supposed to do it ten different times but my question is: How do I make it so I can input 10 different sets of numbers in the same window without it saying "Press any key to continue..." after I input the first set of numbers? If that makes any sense...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
	float A, B, C, Indian, Difference;
	float longSide, shortSide;
	cout << "Enter one side of the triangle" << endl;
	cin >> A;
	cout << "Enter another side of the triangle" << endl;
	cin >> B;
	if(A>B)
	{
		longSide=A;
		shortSide=B;
	}
	else
	{
		longSide=B;
		shortSide=A;
	}
	C = sqrt( pow (longSide,2) + pow (shortSide,2));
	Indian = longSide * (shortSide/2);
	Difference = Indian - C;
	cout << "Pythagorean:" << C << endl << "Indian:" << Indian << endl << "Difference:" << Difference << endl;
system ("PAUSE");
	return 0;
}
You could leave off the "Press any key to continue." just use // to comment out that line. :)
Where on the program do I add that comment
closed account (3qX21hU5)
You could leave off the "Press any key to continue." just use // to comment out that line. :)


I believe he was joking.


@ Aliasteel

Yes it does. You would accomplish this by using what are called loops. There is the while loop, for loop and do while loop http://www.cplusplus.com/doc/tutorial/control/ . What loops essential do is run a section of code repeatedly until a exit condition evaluates to true.

For this problem you could create a index number that you can use as a counter for a while loop. Basically every time the loop goes through a iteration the index should increase by one. Then the while loop condition can be set to not run the loop once the 10th iteration is complete.

For example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
    // This will be our index.
    int index = 0;

    // This is saying run the loop as long as index does not equal 10
    while (index != 10)
    {
        // This is where you put the code you want to run 10 times


        // Make sure to increase the index at the end of each loop.
        ++index;
    }
}
Last edited on
Topic archived. No new replies allowed.