final exams

This is a discussion on final exams within the C Programming forums, part of the General Programming Boards category; I'm studying for my finals. Write a function named check() that has three arguments. The first argument should accept a ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    41

    final exams

    I'm studying for my finals.

    Write a function named check() that has three arguments. The first argument should accept a integer number, second a floating-point number, the third a double-precision number. The body of the function should just display the values of the data passed to the function when it is called.

    Code:
    #include <stdio.h>
    int main()
    {
      void check (int, float, double);
      int firstnum;
      float secnum;
      double thirdnum;
      
      printf("Enter a number: ");
      scanf("%d", &firstnum);
      printf("Great! Please enter a second number: ");
      scanf("%f", &secnum);
      printf("You are almost done, now enter your last number: ");
      scanf("%d", &thirdnum);
    
      check (firstnum, secnum, thirdnum);
    
      return 0;
    }
    void check (int x, float y, double z)
    
    {
      float maxnum;
    
      if (x >= 0)
        maxnum = x;
      else if (y >= 0)
        maxnum = y;
      else if (z >= 0)
        maxnum = z;
    
     printf("\nThe three numbers entered is %.2d %.2f and %.2d\n", maxnum);
    }

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    7
    scanf("%d", &thirdnum);
    printf("\nThe three numbers entered is %.2d %.2f and %.2d\n", maxnum);

    Check it!

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Why even have user input if you don't need it?
    Write a function named check() that has three arguments. The first argument should accept a integer number, second a floating-point number, the third a double-precision number. The body of the function should just display the values of the data passed to the function when it is called.
    It's a one-liner.

    The leftovers from some previous homework are not necessary.

    All you're being asked is to use %d and %f with printf, more or less.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    41
    Quote Originally Posted by Dave_Sinkula
    Why even have user input if you don't need it?
    It's a one-liner.

    The leftovers from some previous homework are not necessary.

    All you're being asked is to use %d and %f with printf, more or less.
    I pretty much figured that, but when I pass my values, I don't get anything that makes sense, i've tried %d %f %f, still isn't giving me anything correct

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Post your attempt.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    41
    Quote Originally Posted by wonderpoop
    I pretty much figured that, but when I pass my values, I don't get anything that makes sense, i've tried %d %f %f, still isn't giving me anything correct
    I got it, i needed to take the maxnum out of the printf and put in firstnum, secnum, thirdnum

    so actually everything above is corred, even the %d, %f, %d, just not the maxnum in my printf

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    65
    yea because if you wanted "maxum" used three times in your printf, you would have to type it three times like...
    Code:
    printf("\nThe three numbers entered is %.2d %.2f and %.2d\n", maxnum,maxnum,maxnum);
    You rant and rave about it, but at the end of the day, it doesn't matter if people use it as long as you don't see.
    People are free to read the arguments, but if the only way for you to discover gravity is by jumping off a cliff, then that is what you're going to have to experience for yourself.
    Eventually, this "fast and loose" approach of yours will bite you one too many times, then you'll figure out the correct way to do things. - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cobwebs in head
    By jmonster in forum C Programming
    Replies: 14
    Last Post: 07-14-2007, 11:39 PM
  2. DirectX dll Final Debug and Final Retail
    By hdragon in forum Tech Board
    Replies: 0
    Last Post: 11-15-2005, 09:46 PM
  3. Final Exams Help
    By DeepFyre in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-15-2005, 06:16 PM
  4. reviewing for final exam, need help with this question
    By jlmac2001 in forum C++ Programming
    Replies: 12
    Last Post: 11-26-2003, 08:37 AM
  5. Final year project
    By khpuce in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 10-10-2003, 08:04 AM

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