Determine largest value and its occurences in an input stream.

If I type in three '5's I get 53 as the highest number and 0 as the number of times that high number appears. If I type in 6, 7, 7 I get 54 as the highest number and 0 as the number of occurrences. Any tips for repairing this program?

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  
#include "stdafx.h"
#include <limits.h>
#include <string>
#include <cstdlib>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
int A[5]={5,6,2,2,6};
 int largestEOF();
 	int a=5;
int smallest;
	 /*int a=1;*///set count to nonzero
	 int numIn=4;
int _tmain(int argc, _TCHAR* argv[])
{
	/* int z;*/

	a=largestEOF();
	cout<<a;
	cin>>A[11];
	return 0;
}

int largestEOF(void)
{
	/*int numIn;*/
	//int smallest;
	/*int count=0;*/
	int largest;
	 int smallest=INT_MIN;
	 //int small=0;

	 int i;

	 int numIn=cin.get();

	cout<<"PLease enter an int.";
	for(int i=0; i<=5;i++){
			if (int a=0||numIn>largest){//if count is zero or numIn is greater than max.
			largest=numIn;//set the new input to max.
			/*cout<<a;*/
			a=1;//we only want to reset the counter to 1 when the new input is greater than previous input
			cin>>numIn;
	/*	cout<<a;*/
		/*continue*/;//return to beginning of while loop
			};//if numIn is greater than largest, assign it to largest.
		//what if the third number is larger than largest? and the fourth number? we'd need to reset the count on the next iteration
		 if (numIn=largest && a<=5){

			a=a+1;//increment a
			cin>>numIn;
			/*cout<<a;*/
			/*continue*/;}
		else if (numIn<largest)//if value entered is less than largest, exit
		{

			cin>>numIn;
			/*cout<<a;*/
			/*continue*/;
		/*else if (numIn<A[i])*/
		/*count++;*/
	
		}	
		if (a=0)
			cout<<"No numbers entered";
		else
		cout<<"the highest num is"<<largest<<"w/ a count of"<<a;
	//count++;}

				return a;	

	}
		}
Topic archived. No new replies allowed.