What is wrong?..!

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2008
Posts: 78
Reputation: jeevsmyd is an unknown quantity at this point 
Solved Threads: 0
jeevsmyd's Avatar
jeevsmyd jeevsmyd is offline Offline
Junior Poster in Training

What is wrong?..!

 
0
  #1
Feb 22nd, 2009
Hello friends.. I am an amateur programmer in TURBO C++ .. It is a very old version v3.0 ... I am beginner.. I wrote a very simple programme to find the largest ans smallest element in an array . .
The largest element finding process is working finely .. I added a watch on MAX and MIN... but out put MIN is wrong..! please help me Pros


Jeevan
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4.  
  5. {
  6. clrscr();
  7. int a[10],n,min,max,i;
  8. cout<<"Enter the number of elements in the matrix \t";
  9. cin>>n;
  10. cout<<"enter the elements of the matrix \n";
  11. for(i=0;i<n;i++)
  12. cin>>a[i];
  13. max=min=a[0];
  14.  
  15. for(i=0;i<n;i++)
  16. if(a[i]>max)
  17. max=a[i];
  18. if(a[i]<min)
  19. min=a[i];
  20. cout<<"Largest is "<<max<<" and Smallest is "<<min;
  21. getch();
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: What is wrong?..!

 
0
  #2
Feb 22nd, 2009
You need more { }
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 78
Reputation: jeevsmyd is an unknown quantity at this point 
Solved Threads: 0
jeevsmyd's Avatar
jeevsmyd jeevsmyd is offline Offline
Junior Poster in Training

Re: What is wrong?..!

 
0
  #3
Feb 22nd, 2009
Hey this is the new code.. Is there anything wrong with this one? I missed the ELSE and a few {}
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4.  
  5. {
  6. clrscr();
  7. int a[10],n,min,max,i;
  8. cout<<"Enter the number of elements in the matrix \t";
  9. cin>>n;
  10. cout<<"enter the elements of the matrix \n";
  11. for(i=0;i<n;i++)
  12. cin>>a[i];
  13. max=min=a[0];
  14.  
  15. for(i=0;i<n;i++)
  16. if(a[i]>max)
  17. {
  18. max=a[i];
  19. }
  20. else if(a[i]<min)
  21. {
  22. min=a[i];
  23. }
  24. cout<<"Largest is "<<max<<" and Smallest is "<<min;
  25. getch();
  26. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: What is wrong?..!

 
0
  #4
Feb 22nd, 2009
And what about the for loop?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: arghasen is an unknown quantity at this point 
Solved Threads: 4
arghasen arghasen is offline Offline
Light Poster

Re: What is wrong?..!

 
0
  #5
Feb 22nd, 2009
hey excuse me but the above code is absolutely fine,i dont find an error it is running fine
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 78
Reputation: jeevsmyd is an unknown quantity at this point 
Solved Threads: 0
jeevsmyd's Avatar
jeevsmyd jeevsmyd is offline Offline
Junior Poster in Training

Re: What is wrong?..!

 
0
  #6
Feb 22nd, 2009
Yeah..There are no problems with the code.. It is working fine.. What is wrong with the for loop?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: What is wrong?..!

 
0
  #7
Feb 22nd, 2009
It's missing { }
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: arghasen is an unknown quantity at this point 
Solved Threads: 4
arghasen arghasen is offline Offline
Light Poster

Re: What is wrong?..!

 
0
  #8
Feb 22nd, 2009
no problem with the for loop as well

maybe sallem gave the coment as u missed the barces of the for loop in your first code
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: arghasen is an unknown quantity at this point 
Solved Threads: 4
arghasen arghasen is offline Offline
Light Poster

Re: What is wrong?..!

 
0
  #9
Feb 22nd, 2009
anyways the problem is now solved so make the thread as solved
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 78
Reputation: jeevsmyd is an unknown quantity at this point 
Solved Threads: 0
jeevsmyd's Avatar
jeevsmyd jeevsmyd is offline Offline
Junior Poster in Training

Re: What is wrong?..!

 
0
  #10
Feb 22nd, 2009
okay buddy..
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC