Thread: I need some help with my program please.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    16

    Unhappy I need some help with my program please.

    Hi! I turned in my program to my professor, but he said that there was improper line spacing & that my program gave the wrong answer for square root of the average.

    If anyone could kindly look at what I have so far & tell me what's wrong with my program, I would greatly appreciate it.

    Thank You Very Much.


    ASSIGNMENT 2

    Write a program which asks the user to enter three numbers from the keyboard, and determines the smallest number, the largest number and (if the sum of all the numbers is not negative) the square root of the sum of all the numbers. If the sum is negative, the program informs the user of that fact.



    The program must work for cases in which all data are negative, all data are positive, all data are the same, or the data are mixed negative and positive values.



    Here's My Program


    Code:
    #include <stdio.h>
    #include <math.h>
    
    /*This program is designed to find the smallest of 3 numbers, the largest,
    
    the average, & the square root of the average.*/
    
    int main()
    
    {
    
    	 float a;  /*a represents 1st number input.*/
    
    	 float b;  /*b represents 2nd number input.*/
    
    	 float c;  /*c represents 3rd numer input.*/
    
    	 float avg; /*avg represents the average of those inputs.*/
    
    	 printf("Please Enter a number. ");
    
    	 scanf("%f",&a);
    
    	 printf("Enter another number. ");
    
    	 scanf("%f",&b);
    
    	 printf("Enter another number. ");
    
    	 scanf("%f",&c);
    
    	 /*This section of the program determines the smallest of the three inputs.*/
    
    	 if((a<b) && (a<c))
    	 {
    
    		printf("%f is the smallest number.\n", a);
    
    	 }
    
    	 if((b<a) && (b<c))
    	 {
    		printf("%f is the smallest number.\n", b);
    	 }
    
    	 else if((c<a) && (c<b))
    
    	 {
    
    		printf("%f is the smallest number.\n", c);
    
    	 }
    
    	/*This section of the program determines the largest of the three inputs.*/
    
    	if((a>b) && (a>c))
    
    	 {
    
    		printf("%f is the largest number.\n", a);
    
    	 }
    
    	 else if((b>a) && (b>c))
    
    	 {
    
    		printf("%f is the largest number.\n", b);
    
    	 }
    
    	 else if((c>a) && (c>b))
    
    	 {
    
    		printf("%f is the largest number.\n", c);
    
    	 }
    
    	 /*This section is in the event the sum of all three numbers are negative.*/
    
    	 if((a+b+c)<0)
    
    	 {
    
    		printf("The sum is negative.\n");
    
    		printf("You can't find the square root of a negative number!\n");
    
    	 }
    
    	 /*This section of the program determines the average of the three inputs.*/
    
    	 avg= (a+b+c)/3;
    
    	 printf("The average of the three numbers is %f\n", avg);
    
    	 printf("The square root of the average is %f\n", sqrt(a+b+c));
    
    
    	 return(0);
    }
    
    /*End of Program*/
    Last edited by agentxx04; 09-25-2004 at 06:57 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM