Re: Beginning programmer... I need some help.



bmlclemson08 wrote:

Hey if anyone could I need to find out how to write a program that
will read in any number of integers, including none, and determine
which is
the largest integer. The part i can't figure out is getting the
program to read any number of integers. Any ideas at all would be
wonderful. here's the code for what i have so far.

#include <stdio.h>

int main ()

int main(void)

is better, as it spells it out for all to see...

{
int current_in, largest_so_far, counter;

printf ("Enter your numbers:\n");

scanf ("%d", &largest_so_far);

for (counter = 2; ; counter=counter+1)

This is a never-ending loop. I suspect that's not what you want.

{
scanf ("%d", &current_in);

Using fgets()/sscanf() combination is safer...


if (largest_so_far<current_in)
largest_so_far = current_in;
else
largest_so_far = largest_so_far;

The `else` part is superfluous.

}
printf ("The largest number is %i.\n", largest_so_far);

return 0;

}


All variables and suuch were determined in my class. I'm guessing my
problem is in the for statement, but I can't figure it out. Thanks
again for any help.

Hint: ask user for a number of integers they want to enter; store that
in your `counter`; while `counter` is > 0 read in number, determine if
it's largest so far, decrement `counter`, rinse, repeat; output
`largest_so_far`.

Cheers

Vladimir


--
You know it's going to be a bad day when you want to put on the clothes
you wore home from the party and there aren't any.

.



Relevant Pages

  • Re: Beginning programmer... I need some help.
    ... bmlclemson08 wrote: ... int main ... All variables and suuch were determined in my class. ... I'm guessing my ...
    (comp.lang.c)
  • Re: Deadlocks on Update
    ... hint if you are not updating the table. ... WITHhint. ... > avalId int 4 No ... CleanCnt:1 Mode: U Flags: 0x0 ...
    (microsoft.public.sqlserver.programming)
  • Re: New to c++.net (need help)
    ... > using namespace std; ... > int main ... Here's a hint for when ... your program is behaving other than how you expect, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Bit fiddling
    ... int n; should be unsigned int n;, or a better solution would have ... Hint #2: Is the value of ~3 even or odd? ... divisibility-by-three test would make a useful improvement. ... On the six-year-old machine sitting in front of me at the ...
    (comp.lang.c)
  • Re: Reading some pieces of a file
    ... ron wrote: ... find how to open and read a file (hint: ... read the answer and compare ... int main ...
    (alt.comp.lang.learn.c-cpp)