smallest integer program, help please

This is a discussion on smallest integer program, help please within the C Programming forums, part of the General Programming Boards category; This program is supposed to give you back the smallest integer. See you put in a number, and that will ...

  1. #1
    STUDENT2
    Guest

    Angry smallest integer program, help please

    This program is supposed to give you back the smallest integer. See you put in a number, and that will specify how many you will be allowed to put in before the program decides the smallest. My program compiles and runs, but it does not give me the right value back all the time. Try it and help, please. thanks

    This isn't giving me the right return, it gives me wierd outputs, it doesn't give me the smallest, I think my counter may be wrong
    -------------------------------
    Code:
    #include <stdio.h>
    
    int main()
    {
     int firstValue=0, currentNumber, counter=0, smallestNumber;
    
     printf("Please enter a positive  integer value.  the first value you enter is the number of integers you will be allowed to enter further.\n");
     
     scanf("%d", &firstValue);
     
     while ( counter <= firstValue ) 
     {
        printf( "Enter integer: " );
    
     
        scanf( "%d", &currentNumber );
        smallestNumber = firstValue;
     
        if ( smallestNumber > currentNumber )
           smallestNumber = currentNumber;
        counter= counter + 1;
     }
    
     /*termination phase*/
     printf( "The lowest integer value you put in is %d/n", smallestNumber );
     return 0;
    }
    tagged by Salem

  2. #2
    STUDENT2
    Guest
    my other program is jacked up too. I am supposed to do a factorial of number the user puts in and it should print out like this, for example if you use 4!:
    1 1
    2 2
    3 6
    4 24
    (that is like a tabular format).
    Anyone who can help a brother out, thanks, this is my first week of programming learning for real, ever. This is rough but I think I can get good at. If it is not appropriate to ask for help in this manner, then chew me out. PEACE! later, thanks for your time too. But the one I posted above, I know it has to be such a small glitch in my arrangement.
    --------------------------------------------

    #include <stdio.h>
    #include <math.h>

    int main()
    {
    int answer, factorial, counter=0;

    printf( "please put in the number, and you get the factorial table.\n");

    scanf( "%d", &factorial );

    if ( factorial==0 )
    printf( "1 1");

    if ( factorial ==1 )
    printf( "1 1");

    for ( counter =1 ;counter=factorial; counter++ )
    {
    answer = counter*factorial; }

    printf( "%d", counter );
    return 0;
    }

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    Code:
      while ( counter <= firstValue ) 
     {
        printf( "Enter integer: " );
    
     
        scanf( "%d", ĄtNumber );
        smallestNumber = firstValue;
    It looks like this section of code will not do what you wish it to do.
    No matter what number your user puts in, firstValue will always be the smallest number. It appears your current number will never be evaluated.

    Try messing with this part.

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    Code:
      for ( counter =1 ;counter=factorial; counter++ )
    {
    answer = counter*factorial; }
    
    printf( "%d", counter );
    return 0;
    It appears from this code, the only thing your project is going to print out is the counter, if it ever gets there. Look at your for loop, correct it, then figure out a way to print the data out.

    HINT: you need to print out each iteration and it would probably be a good thing to print your answer.

  5. #5
    STUDENT2
    Guest
    ok, i will try to look at those things, thanks.
    What does "tagged" mean at the bottom of my first post, Salem did it. And oh yeah, Salem, SALAM! Peace

  6. #6
    back? dbaryl's Avatar
    Join Date
    Oct 2001
    Posts
    597
    "tagged" - If you conpare your 1st post and your other ones, you will see that the code is formatted differently. To do this, use the [code] [/code] tags. Simply put your code within those tags, and it will tab your code over, teh whole deal.

    Like so:
    Code:
    //your code here
    More on that here in the FAQ.
    This is my signature. Remind me to change it.

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    4
    Originally posted by STUDENT2
    ok, i will try to look at those things, thanks.
    What does "tagged" mean at the bottom of my first post, Salem did it. And oh yeah, Salem, SALAM! Peace
    I used tags here to quote you. If you click his link up there, there is a brief page on it. All it means, is that he tagged your code so it is all properly indented. Compare your first post with the second, and note the difference in the look of the code. Just easier to read, is all...

  8. #8
    STUDENT2
    Guest

    Talking

    cool, now can someone help me with my homework just as quick?
    I THINK NOT!

  9. #9
    STUDENT2
    Guest

    Talking

    salem!
    your name means "peace" in some languages. It's also the name of a local methodist church, and also the name of a brand of cigarettes(which I despise)

  10. #10
    STUDENT2
    Guest
    yes its my first week, well, I can learn by example too. But I guess I will follow my own experiences. Yeah, you guys know what is best for me, I won't learn this way. But good grades, yeah, I like them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 02:42 AM
  2. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  3. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  4. Writing code for a program in C
    By Sure in forum C Programming
    Replies: 7
    Last Post: 06-11-2005, 02:33 PM
  5. Linked Lists Integer addition ? HELP Please??
    By green_eel in forum C Programming
    Replies: 3
    Last Post: 03-12-2003, 04:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21