WHY IS MY MAX VALUE NOT WORKING WITH THIS CODE include inclu

WHY IS MY MAX VALUE NOT WORKING WITH THIS CODE

#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main()
{


   int value,sum=0,average,count=0,min=0,max=0;

       

  
   min=value;
   max=value;

  
   if(value!=0)
   {
       do
       {
          
  
            cout<<\"Enter a Number :\";
   cin>>value;
   cout<<value<<endl;
              count++;
         
  
           sum+=value;
         
          
         
          
           if(value!=0)
           {
           if(value>max)
       max=11;
        if(value<min)
       min=value;
           }
                 
       }while(value!=0);
   }
   else
   {
     
       cout<<\"** NO data so no answers **\"<<endl;
       exit;

Solution

Hi,

I have updated yoour code. it will work now. Highlighted the code changes below.

#include <iostream>
#include <iomanip>
#include <climits>
#include <stdlib.h>
using namespace std;

int main()
{


int value,sum=0,average,count=0,min=INT_MAX,max=INT_MIN;
do
{
  
  
cout<<\"Enter a Number :\";
cin>>value;
count++;

  
sum+=value;

  

  
if(value!=0)
{
if(value>max)
max=value;
if(value<min)
min=value;
}

}while(value!=0);
cout<<\"Max is \"<<max<<endl;
cout<<\"Min is \"<<min<<endl;

}

Output:

sh-4.3$ g++ -std=c++11 -o main *.cpp                                                                                                                                                                                             

sh-4.3$ g++ -std=c++11 -o main *.cpp                                                                                                                                                                                             

main                                                                                                                                                                                                                             

sh-4.3$ main                                                                                                                                                                                                                     

Enter a Number :5                                                                                                                                                                                                                

Enter a Number :4                                                                                                                                                                                                                

Enter a Number :1                                                                                                                                                                                                                

Enter a Number :2                                                                                                                                                                                                                

Enter a Number :3                                                                                                                                                                                                                

Enter a Number :7                                                                                                                                                                                                                

Enter a Number :6                                                                                                                                                                                                                

Enter a Number :0                                                                                                                                                                                                                

Max is 7                                                                                                                                                                                                                         

Min is 1

WHY IS MY MAX VALUE NOT WORKING WITH THIS CODE #include <iostream> #include <iomanip> #include <stdlib.h> using namespace std; int main() { in
WHY IS MY MAX VALUE NOT WORKING WITH THIS CODE #include <iostream> #include <iomanip> #include <stdlib.h> using namespace std; int main() { in
WHY IS MY MAX VALUE NOT WORKING WITH THIS CODE #include <iostream> #include <iomanip> #include <stdlib.h> using namespace std; int main() { in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site