Thread: Problem with a simple program

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C noobie
    Join Date
    Jun 2006
    Location
    MI
    Posts
    25

    Problem with a simple program

    Alright, I just started teaching myself how to program C a couple days ago, so don't make fun of me too much!


    Code:
    #include <stdio.h>
    
    
    //purpous is to have 4 numbers input and the average displayed
    
    
    main()
    {
    	int a = 1;  //counter
    	double b;   //numbers to be input
    	double c = 0.0;   //total of all b
    	char d;  //suffix to number
    
    	while(a < 5)  
    	{
    		printf("Input your %d%c number: ",a,d==1?'st':(a==2?'nd':(a==3?'rd':'th')));   //input numbers
    		scanf("%fl",&b);  //input numbers to be averaged
    		c = c + b;  //add all the numbers up
    		++a;  //tell program to go to next number
    		if (a<5) continue;	//if not done inputting numbers, loops	
    		printf("The average of the 4 numbers is %fl.",c/4);  //displays average of the sum of all 4 numbers inputted
    	}
        
    	return(0);
    	
    }
    My problem is the program goes goofy when displaying the final averaged number. Does it have to do with the "Double"? Im getting a result a 0.0000001. Also it displays "t" at the end of each number when displaying which number to input.
    Last edited by Salgat; 06-15-2006 at 04:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with a simple program
    By alfredd in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2009, 03:48 PM
  2. 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
  3. Replies: 1
    Last Post: 12-30-2007, 10:08 AM
  4. Running Program Problem
    By warfang in forum C++ Programming
    Replies: 10
    Last Post: 03-28-2007, 02:02 PM
  5. simple login program problem
    By suckss in forum C Programming
    Replies: 11
    Last Post: 11-11-2006, 05:02 PM