Thread: Help with a small program

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    2

    Unhappy Help with a small program

    I need some help writing a program that inputs three different integers from the keyboard, then prints the sum, the average, the product, the smallest and the largest of these numbers. Using only the single-selection form of the IF statement. If someone could help me it would be greatly appreciated.

  2. #2
    Unregistered
    Guest
    sum = a + b + c
    average = (a + b + c) / 3
    product = a*b*c
    smallest: assume first is smallest, and then test, using if, and make one of the others the smallest, if so

  3. #3
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Posts
    77
    Code:
    #include <stdio.h>
    
    void main()
    {
    	int a,b,c,product;
    	float average,sum;
    
    	printf("\n\tInteger 1: ");
    	scanf("%i",&a);
    	printf("\n\tInteger 2: ");
    	scanf("%i",&b);
    	printf("\n\tInteger 3: ");
    	scanf("%i",&c);
    
    	sum=a+b+c;
    	average=sum/3;
    	product=a*b*c;
    
    	printf("\n\n\tSum: %.0f",sum);
    	printf("\n\tAverage: %.3f",average);
    	printf("\n\tProduct: %i",product);
    }
    I was too lazy to type out the Smallest/Largest part of the program...read his above post...you can figure it out.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >void main()
    Never use void main, the result is undefined. The proper declaration for main is either int main ( void ) or int main ( int argc, char *argv[] )

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    I was about to say the same thing, Prelude.

    I hope they didn't teach you that in programming class, SavesTheDay.

  6. #6
    Unregistered
    Guest
    they taught ME that in programming class! void main...*shakin my head* shame u can learn more on the net for $19.99/mo. than I learn @ school for $12,000/year lol



    *dust*

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >they taught ME that in programming class!
    You'll be hard pressed to find a good class on C, very few teachers actually know how to program correctly and portably. I walked out on a class and dropped out of it the next day because the instructor recommended use of fflush ( stdin ) to clear the garbage left behind by scanf.

    Right idea, wrong method. Hopefully I screamed at him enough to change his mind about fflushing input streams ;D And books are the same way, you have to look pretty hard to find a book on C that is actually worth the exorbitant prices they ask for.

    -Prelude
    My best code is written with the delete key.

  8. #8
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59
    Prelude ... just wondering if you know of any good C books you would recommend,

    "that is actually worth the exorbitant prices they ask for"

    cause i am having a hard time finding a good one thats worth paying for, and reading. as you just pointed out.

    Any suggestions would be helpful, thx

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    The C Programming Language is worth the money, as are
    Pointers on C by Kenneth Reek
    Algorithms in C by Robert Sedgewick
    Writing Solid Code by Steve Maguire
    Expert C Programming by Peter Van Der Linden
    C Unleashed by Richard Heathfield, Lawrence Kirby, et al.
    The C Standard Library by P. J. Plauger
    and I've been told that C How to Program by Deitel and Deitel is good, though it's the most expensive of all of them.

    C Unleashed is a personal favorite of mine, partly because I know most of the authors personally
    Algorithms in C is an absolute must, no questions asked. Though it is hard to follow if you don't have a firm grasp of the basic syntax.
    Writing Solid Code is good for writing clean and bugless code, the constructs offered are very useful.
    Expert C Programming would be a good read even if it didn't contain information that normally would take years of hard core experience to learn.
    Pointers on C is a wonderful introductory book and reference material. It explains pointers well and early, which are two items that make it a keeper. I find this one useful even now, being well past the introductory phase.
    The C Programming Language...written by the creator of the language, need I say more?
    The C Standard Library is excellent for both learning how to use the standard library to its fullest as well as reading about how each function is implemented with full source code! I don't even have to tell you how useful that is.

    -Prelude
    My best code is written with the delete key.

  10. #10
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59
    Prelude ... thanks for the reply, and the good variety of seemingly complete and beneficial books to check into.

    Im sure this list will help myself, and others, now and in the future.


  11. #11
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    I have C: How to program by Deitel and Deitel, and i luv the exercises in EACH chapter, though out of many times i have to seek help, but i find that it's through doing exercises that u learn, not plainly by reading .

    To Prelude:
    Did u actually meet the authors? Just curious, how did u meet them?

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    I've met a couple of them at conventions and similar functions, but for the most part through the net by email, chat and forums. The easiest way to meet an author is to go onto Usenet and post. Richard Heathfield, Lawrence Kirby and Ben Pfaff are all regular contributers to comp.lang.c

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please Help with small program
    By cjohnman in forum C Programming
    Replies: 11
    Last Post: 04-14-2008, 09:59 AM
  2. Program to reverse a number. small error with it..
    By comproghelp in forum C Programming
    Replies: 8
    Last Post: 11-22-2004, 10:52 AM
  3. Help writing small program
    By guitarhead2000 in forum C++ Programming
    Replies: 2
    Last Post: 10-13-2004, 12:42 PM
  4. A little Help with a small program
    By whtpirate in forum C Programming
    Replies: 7
    Last Post: 06-05-2003, 06:15 PM
  5. Very small program...Whats wrong???
    By SmokingMonkey in forum C++ Programming
    Replies: 4
    Last Post: 05-30-2003, 09:09 PM