Using counter to find largest number( better code now)

When I get to the largest number its a bunch

Page 1 of 1

1 Replies - 28053 Views - Last Post: 12 February 2007 - 03:31 PM Rate Topic: -----

#1 agentjk  Icon User is offline

  • New D.I.C Head

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

Using counter to find largest number( better code now)

Post icon  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)

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1