To find which variable is greater

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 23
Reputation: th3learner is an unknown quantity at this point 
Solved Threads: 1
th3learner th3learner is offline Offline
Newbie Poster

To find which variable is greater

 
0
  #1
Oct 10th, 2009
Can anyone tell whats wrong in below code?

I m learning c++ ..so maybe this ll be very easy solution for you guys
  1. Hello i m learning c++ ..so maybe this ll be very easy solution for you guys
  2.  
  3. #include<iostream.>
  4. #include<conio.h>
  5. void main()
  6. {
  7. int a,b,c;
  8. clrscr();
  9. cout<<"Enter Your 1st Value";
  10. cin>>a;
  11. cout<<"Enter Your 2nd value";
  12. cin>>b;
  13. cout<<"Enter your 3rd value";
  14. cin>>c;
  15.  
  16. if(a>b&&c)
  17. {
  18. cout<<"1st value is greater";
  19. }
  20. else if(b>a&&c)
  21. {
  22. cout<<"2nd value is greater";
  23. }
  24. else if(c>b&&a)
  25. {
  26. cout<<"3rd value is greater";
  27. }
  28.  
  29. getch();
  30. }
Last edited by th3learner; Oct 10th, 2009 at 1:25 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: bobbytommathew is an unknown quantity at this point 
Solved Threads: 0
bobbytommathew bobbytommathew is offline Offline
Newbie Poster
 
0
  #2
Oct 10th, 2009
replacements:

int main()
{
using namespace std;
int a,b,c;
//Take out clrscr(); from this line, hope this works
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,844
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster
 
1
  #3
Oct 10th, 2009
This isn't a code snippet. If possible, please change the thread type to a regular old thread as opposed to a code snippet.

The && operator doesn't work that way. You want something like this:

  1. if (a > b && a > c)
  2. cout << "First value is the max.";
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 23
Reputation: th3learner is an unknown quantity at this point 
Solved Threads: 1
th3learner th3learner is offline Offline
Newbie Poster
 
0
  #4
Oct 10th, 2009
@VernonDozier

Thanks for helping me...your code works

@bobbytommathew
thanks for your tips
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 266 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC