Connecting Tech Pros Worldwide Forums | Help | Site Map

C++ progrrame to find the greates integer...

snehil's Avatar
Newbie
 
Join Date: Jun 2009
Location: New Delhi, INDIA
Posts: 6
#1: Jun 29 '09
Hi.. I'm a very beginner in C++
I was trying to make a programme to find biggest of three nos. but the programme dat i made is not returning the desired solutin. Pls help me out with this..and also please explain the problem to me.. Thanx..in advance...
Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,b,c;
  7. cout<<"Please enter three nos. ";
  8. cin>>a>>b>>c;
  9. if (a>b)
  10.  {
  11.   if (a>c)
  12.   cout<<"a is largest";
  13.   else
  14.   cout<<"c is largest";
  15.  }
  16. else if (b>c)
  17. cout<<"b is largest";
  18.  
  19. getch();
  20. }
  21.  
The problem is that when a and b are largest.. theres no error.. but when c is greatest. there is problem some times..
for instance.. when i input.. a=89, b=59, c=99
C is displayed as largest..
but when I am inputting a=59, b=89, c=99
there is no out put coming... :-/

snehil's Avatar
Newbie
 
Join Date: Jun 2009
Location: New Delhi, INDIA
Posts: 6
#2: Jun 29 '09

re: C++ progrrame to find the greates integer...


Solved..
I was missing a statement..silly me...
Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,b,c;
  7. cout<<"Please enter three nos. ";
  8. cin>>a>>b>>c;
  9. if (a>b)
  10.  {
  11.   if (a>c)
  12.   cout<<"a is largest";
  13.   else
  14.   cout<<"c is largest";
  15.  }
  16. else if (b>c)
  17. cout<<"b is largest";
  18. else
  19. cout<<"c is largest";
  20. getch();
  21. }
  22.  
this programme is now working fine.. :)
Reply

Tags
c++, greatest of, integers, largest of