Thread: conversion errors

  1. #1
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002

    conversion errors

    #include <stdio.h>
    int average(int a, int b, int c, int d, int e);
    int main (void)
    	int a;
    	int b;
    	int c;
    	int d;
    	int e;
    	float f;
    	printf("Enter five numbers\n");
    	scanf ("%d", &a, &b, &c, &d, &e);
    	f = average(a,b,c,d,e);
    	printf("The average of the numbers you entered is %.2f\n",f);
    	return f;
    int average(int a, int b, int c, int d, int e)
    	return (int) (a+b+c+d+e)/5;
    Why am I receiving conversion errors with this code?

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Average returns an int, but you put it in a float, then you try to return a float from main, which is defined to return int.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    >>scanf ("%d", &a, &b, &c, &d, &e);
    Not enough formats here, try
    >>scanf ("%d %d %d %d %d", &a, &b, &c, &d, &e);

    The return type of the average function is also wrong. Your confusing int's and float's.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does C need pointer conversion
    By password636 in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 07:33 AM
  2. Errors with header files in OpenGL using VisualC++
    By wile_spice in forum Game Programming
    Replies: 3
    Last Post: 06-22-2006, 08:56 AM
  3. Configurations give different results
    By Hubas in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2003, 11:43 AM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 12:43 PM
Website Security Test