unable to print

This is a discussion on unable to print within the C Programming forums, part of the General Programming Boards category; hi everyone. im new here. this my code: Code: #include <math.h> double main() { double num1; double num2; printf ("enter ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    11

    unable to print

    hi everyone. im new here.
    this my code:

    Code:
     #include <math.h>
    
    
    double main()
    {
    
        double num1;
        double num2;
    
    
        printf ("enter number 1: \n");
        scanf("%e" , &num1);
        printf("enter number 2 \n");
        scanf("%e", &num2);
    
         double arithmetic_mean = (( num1 + num2)/2);
            printf ("Arithmetic Mean is :  \n", arithmetic_mean);;
    
         double geometric_mean =  sqrt (num1 * num2);
            printf ("Geometric Mean is  : \n" , geometric_mean);
    
    
         double harmonic_mean = 2 / ( 1 / num1)+ (1 / num2);
            printf (" Harmonic Mean is : \n", harmonic_mean);
    
    
    return (0);
    }
    when i run the program i am unable to print anythin on the last 3 prinf's it just comes up as blank.
    how can i correct this?

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,917
    First you need to include stdio.h for the standard input/output functions. Second main must be defined to return an int, not a double and should return an int. Third in your scanfs you are using the format specifier "%e" which works for a float but you are using a double so the specifier should be "%le" or "%lf". The printfs you have a variable you want to print but you don't have the specifier in the format string:
    Code:
    printf (" Harmonic Mean is : %e\n", harmonic_mean);
    You should look at these links for scanf and printf.

    Jim

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    11
    thanks alot

    i jus started c in uni.
    make many mistakes

    nehal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Towr of Hanoi move the disc
    By WatchTower in forum C Programming
    Replies: 9
    Last Post: 07-17-2009, 04:48 AM
  2. Queues
    By ramayana in forum C Programming
    Replies: 22
    Last Post: 01-01-2006, 02:08 AM
  3. Bypassing Print Dialog Box
    By leojose in forum Windows Programming
    Replies: 0
    Last Post: 10-13-2005, 07:44 AM
  4. Replies: 1
    Last Post: 07-31-2002, 12:35 PM
  5. How to print out the data throw printer.Attn Salem
    By Jason in forum C Programming
    Replies: 2
    Last Post: 09-23-2001, 06:58 AM

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