Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,046 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,523 people online right now. Registration is fast and FREE... Join Now!




Accept 3 integers & print largest amongs them

 
Reply to this topicStart new topic

Accept 3 integers & print largest amongs them

Nikita S Anbhavane
5 Aug, 2008 - 05:31 AM
Post #1

New D.I.C Head
*

Joined: 5 Aug, 2008
Posts: 1

cpp
void main()
{
int a,b,c;
printf("Enter three integers");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
if(a>c)
printf("a is the largest");
else
printf("c is the largest");
else if(b<c)
printf("b is the largest");
printf("c is largest");
}

Mod edit: Please code.gif
Thanks, gabehabe smile.gif
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Accept 3 Integers & Print Largest Amongs Them
5 Aug, 2008 - 05:32 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
Do you have a question regarding the posted code?
User is offlineProfile CardPM
+Quote Post

penguin2
RE: Accept 3 Integers & Print Largest Amongs Them
5 Aug, 2008 - 06:35 AM
Post #3

D.I.C Head
Group Icon

Joined: 22 Jul, 2008
Posts: 79



Thanked: 1 times
Dream Kudos: 25
My Contributions
You need to use brackets for the if statements, like this:
CODE

if(thing1=thing2) {
   whatever();
} else {
   verb();
}

User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Accept 3 Integers & Print Largest Amongs Them
5 Aug, 2008 - 10:21 AM
Post #4

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,522



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
I think you need to read up on if statements. Here:
cpp
#include <stdio.h>

int main () // main should always return int!!!
{
int a,b,c;
printf ("Enter three integers. . .\n");
scanf ("%d%d%d",&a,&b,&c);
if (a > b && a > c)
printf ("a is the largest");
else if (b > a && b > c)
printf ("b is the largest");
else
printf ("c is the largest");
return 0;
}

Hope this helps smile.gif
User is offlineProfile CardPM
+Quote Post

AfterBurner66
RE: Accept 3 Integers & Print Largest Amongs Them
5 Aug, 2008 - 03:08 PM
Post #5

New D.I.C Head
*

Joined: 2 Aug, 2008
Posts: 17


My Contributions
You can also use ternary operator for more compact code(I'll give the whole procedure of comparing as a function):

CODE
int max(int a,int b,int c)
{
return (a>b)?((a>c)?a:c):((b>c)?b:c);
}


and that's all there is to it!This solution is not as cryptic as it seems!Enjoy!

This post has been edited by AfterBurner66: 5 Aug, 2008 - 03:09 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 05:07PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month