eda Subj : Re: Random Integer Solutions...Help Please... To : borland.public.cpp.borlandcpp From : Ed Mulroy [TeamB] Date : Mon Jun 28 2004 09:12 pm You originally were reading the number of inputs like this: scanf("%d", &d); I told you of a problem with that, how the enter (the '\n') will be left in the buffer. I gave you two solutions, do a getchar(); or read into a char string (a buffer) with fgets and use sscanf. Since then your code has the declaration for the buffer and sscanf but no fgets. It retains the scanf and adds the getchar(). Change this code, prompting the user for and reading the number of inputs, ------------- int a; char buffer[133]; printf("Input the number of integers you will input,\nand I will tell you the smallest of the group: "); scanf("%d", &a); sscanf(buffer, "%d", &a); ------------- Change it to one of: ------------- int a; printf("Input the number of integers you will input,\n" "and I will tell you the smallest of the group: "); scanf("%d", &a); getchar(); ------------- OR ------------- int a; char buffer[133]; printf("Input the number of integers you will input,\n" "and I will tell you the smallest of the group: "); fgets(buffer, sizeof(buffer), stdin); sscanf(buffer, "%d", &a); ------------- The loop that follows that has a problem. The current code is: ------------- for ( ;a > 0; --a) printf("The smallest number is %d\n", &buffer); ------------- What must be done in the loop is to read the value of a number, compare it to the variable in which the smallest number is stored and if this new number is smaller, set that smallest number variable to this new number's value. The current code executes a printf statment 'a' times. The format string for the printf statement tells printf to write the value of an integer but the value it is given is the address of the char string variable 'buffer'. The code should look something like this: ------------- for ( ; a > 0; --a) { /* executable code to read in a number, */ /* test if it is smaller than the smallest value */ /* and if it is, assign it to the smallest number variable */ } /* code to write the smallest number */ ------------- Somewhere near the top you will need to add a declaration for the variable to hold that smallest number. If working in C and not C++, that will have to be up at the top where the other variable declarations are found. .. Ed > Jeremy Pham wrote in message > news:40e09074$1@newsgroups.borland.com... > > Here's my revisions so far: > > #include > > main() > { > int a; > char buffer[133]; > > printf("Input the number of integers you will input,\nand I > will tell you the smallest of the group: "); > scanf("%d", &a); > sscanf(buffer, "%d", &a); > > for ( ;a > 0; --a) > printf("The smallest number is %d\n", &buffer); > > getchar(); > printf("Press enter..."); > getchar(); > return 0; > } > > I'm not exactly sure myself how to determine the calculation > in figuring out the smallest integer. Maybe you can help with that? > > BTW, This actually isn't a school assignment...school is kind > of long over anyways. I'm just a high school student learning > the C Programming Language on his own time from the book > "C How to Program by: Deitel & Deitel Associates." And I'm > on the excercises section at the end of the current chapter I'm > on, and these excercises I find, are really difficult. Maybe > you can be more English than Computers with this stuff? I'm > kind of new sorry. Possibly even...tell me the answer? > > Once again, thanks Ed. > Jeremy Pham . 0