# Using counter to find largest number( better code now)

Page 1 of 1

## 1 Replies - 29638 Views - Last Post: 12 February 2007 - 03:31 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=23883&amp;s=301198ebf2ecf87560499b884357aa38&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 agentjk

Reputation: 0
• Posts: 37
• Joined: 11-February 07

# Using counter to find largest number( better code now)

Posted 12 February 2007 - 02:37 PM

Okay, I need to use 3 variables: largest, number, and counter...to find the largest of ten numbers. This is what I have so far, I think I'm close but I could be way off.
```#include <stdio.h>

int main()

{
int counter = 1;
int largest = 0;
int number = 0;

printf("Enter 10 integers\n");

while(counter <= 10)
{

scanf_s("%d", &number);

if(number >= largest)
{
largest = number;
}
else(number <= largest);
{
largest = largest;
}

counter++;
}

printf("The largest number is %d\n", &largest);

return 0;
}

```

This post has been edited by agentjk: 12 February 2007 - 03:17 PM

Is This A Good Question/Topic? 0

## Replies To: Using counter to find largest number( better code now)

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: Using counter to find largest number( better code now)

Posted 12 February 2007 - 03:31 PM

Did you have a specific question?

As an FYI, the if else structure does not take a condition on the else portion. Else means that anything not captured by the if portion will be captured. If you wish to specify a secondary condition, you will have to use an if else if else structure. Finally, the two conditions specified in your code overlap. This could cause undefined behaviour.