Displaying the highest value

Hello,
I'm having a hard time getting my program to show the largest value out of a series of user prompted values. I need to have my program be able to ask the user for the input an infinite amount of times, but be able to stop the program and display the largest value.

The code I have now will only display the previous result.

Here is my code.

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
29
30
31
32
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main ()
{
	double a, b, c = 0, answer1 = 0;
	string answer = "no answer", a1;
	do 
	{
		cout << "Please enter the length of side a: ";
		cin >> a;
		cout << "Please enter the length of side b: ";
		cin >> b;
		c = sqrt(pow(a,2) + pow(b,2));
		cout << "side c is " << c << endl;
		if (c > answer1)
		{
			answer1 = c;
			cout << "Do you want to continue (\"Yes\" or \"No\")?";
			cin.ignore();
			getline(cin,a1);
			if (a1 == "No")
			{
			cout << "The largest answer for side c was " << answer1 << endl;
			break;
			}
		}
	}
		while (answer != "No");
	
	}
1
2
3
4
5
6
7
8
int input, big = 0;
while(cin >> input)
{
	if(input > big)
		big = input;
}

cout << "The biggest number input: " << big << '\n';


You could use something like this.
Topic archived. No new replies allowed.