small prob

I have this problem in this code
my problem in min value !!

and i want to count the values but when the value is bigger than 50 !!



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
#include<iostream>
using namespace std;

int main()

{
	double value,min,max,avg,sum;
	int count;
	int Degree;

	count=0;
	min=0.0;
	max=0.0;
	sum=0.0;


	cout<<"put your value ^_^ ,if you want stope put -1 like a value please "<<endl;
	cin>>value;
	
	
		
		while(value!=-1)//if you want stope put -1 like a value please
		
		{	
			
			sum +=value;
		count++;//for count the value 
			
			if(value>max)

				max=value;

			else if((value<max)&&(value>0))// have a problem here 

				min=value;
			
			cin>>value;
	
		}
		

	
	cout<<" the max value is : "<<max<<endl;
	cout<<"the min value is : "<<min<<endl;
	cout<<"the sum is  :"<<sum<<endl;
	cout<<"the count is : "<<count<<endl;
	

	avg=sum/count;

	cout<<"the avg is "<<avg<<endl;


	cout<<"enter your Degree please "<<endl;
	cin>>Degree;

if(Degree>=avg)

	cout<<"pass"<<endl;

else
	cout<<"Failed"<<endl;



	system("pause");
	

	return 0;

}


?? please it's in min only !
As far as I understood about your problem, it's about min value. If so, you could do following:
put this code in line 20

1
2
 while(value < 0) cin >> value;
           min = value;

And replace below code with the code snip of line 33

else if((value < min) && (value > 0))
Last edited on
mmmm no that's wrong

it give me 0 !!

because that's the initializes value !!
i dont know if i understood right but :
else if((value<max)&&(value>0))// have a problem here
if you want the minimum value then dont initialise min with 0. initialise it with the first value you read:(also for max)
1
2
3
4
5
6
cout<<"put your value ^_^ ,if you want stope put -1 like a value please "<<endl;
	cin>>value;
	
	//HERE
min=value;max=value;
		


and in your code test for
1
2
3
4
5
if(value>max)

				max=value;
else if (value<min)
min=value;
Last edited on
I normally like to assign min and max to the first value read so after you read the first value on line 18 add
1
2
min = value;
max = value;


Also you should be checking min and max separately without the else.

1
2
3
4
if(value >= max)
   max = value;
if(value <= min)
   min = value;


ok i will try it ,

but what about the second question ( the count ) !!
What do you suggest, sounds fairly easy to me?
I don't know how much skill do you have about C++ and why even can't run a code. But my code wasn't wrong. The min will be initialized with first value you input. Then next values will be tested whether is each one bigger or smaller and ...
oh am sorry am already change the all code and it's right ^_^ thx for all
Topic archived. No new replies allowed.