hey all,

first post of a beginner coder ;),

I keep geting the following error : conflicting types of 'graphic_choice'.. its not a warning so it wont compile. I haven't finished case 7 so that may have some syntax issues.

hope this isn't to big of a code block? i just deleted the contents of the working functions

#include <stdio.h>
#include <stdlib.h>

main()


{
  int menu(); /* function to select option*/
 
  void input_distances(int distance_array[],int num);
  void display_distances(int distance_array[],int num);
  void average_calc(int distance_array[],int num);
  void min_max(int distance_array[],int num);
  void top_three(int distance_array[],int num);
  void converter(int distance_array[],int num);
  void sorted_graphic(int distance_array[],int num);
  void unsorted_graphic(int distance_array[],int num);
  char graphic_choice();

  int input_num_of_drivers();

  float* distances;

  int i;
  int num_drivers, num_of_bytes;
  int option ;
  char x;

  do
  {
    option=menu();

    switch (option)
    {
    case 0:
      break;
    case 1:

      num_drivers=input_num_of_drivers();
      num_of_bytes=num_drivers*sizeof(float);
      distances=malloc(num_of_bytes);

      if ( distances == NULL )
      printf("Cannot Allocate Memory\n");

      input_distances(distances,num_drivers);
      break;

   case 2:
      display_distances(distances,num_drivers);
      break;

    case 3:
    average_calc(distances,num_drivers);
    break;

    case 4:
    min_max(distances,num_drivers);
    break;

    case 5:
    top_three(distances,num_drivers);
    break;

    case 6:
    converter(distances,num_drivers);
    break;

    case 7:
    graphic_choice();

            /*choice = graphic_choice();
            switch (choice)
            {
                case 'y' || 'Y':
                sorted_graphic(distances,num_drivers);
                break;

                case 'n' || 'N':
                unsorted_graphic(distances,num_drivers);
                break;
            }*/
    if ( x == 'y'||'Y')
    sorted_graphic(distances,num_drivers);
    if ( x == 'n'||'N')
    sorted_graphic(distances,num_drivers);
    else
    printf ( "Please select Y or N");

    break;

    }
  }
  while (option!=0);
}
/*free (distance_array);*/
int menu()

/*
Purpose: display menu options
Parameters: none
Returns: a valid option
*/

{
int opt;

  printf ("Press 1 to enter number of drivers and distances\n");
  printf ("Press 2 to display stored information\n");
  printf ("Press 3 to show the average distance\n");
  printf ("Press 4 to show the min / max distances\n");
  printf ("Press 5 to show the three longest distances\n");
  printf ("Press 6 to Convert thedistances to miles\n");
  printf ("Press 7 for a graphical display of the information\n");
  printf ("Press 0 to Exit\n");
  printf("\n");
  printf("Choice:");
  scanf("%d", &opt);
  printf("\n");
return opt;
}

input_num_of_drivers()
{
int num;
    printf( "Enter the number of drivers:" ) ;
    scanf( "%d", &num ) ;
    printf("\n");
return num;
}


void input_distances(int distance_array[],int num)
{

{

}

void average_calc(int distance_array[],int num)
{

}

void min_max(int distance_array[],int num)

{

}

void top_three(int distance_array[],int num)
{

}

void converter(int distance_array[],int num)

{

}

sorted_graphic(int distance_array[],int num)

{
{

unsorted_graphic(int distance_array[],int num)
{

}

graphic_choice( char x )

{

char choice;

    printf(" Would you like the data sorted, Y or N: ");
    scanf("%c", &choice);
/* return choice*/

}

Edited 5 Years Ago by l1ttledb: n/a

Hi,

line 19 prototype, return type is char, line 172 implementation no return type.

Changed it to return type char and everybody will be happy :)

Welcome to Daniweb.

graphic_choice( char x )

This could be the problem(line 172). Try this

char graphic_choice( char x )

hi, thanks for the reply,

pulling my hair out here over something that should be straightforward..

not sure what u mean though, so my prototype is fine but where do i change my return type in the function?

edit: think its ok, how come i had to put char graphic_choice( char x ), i didn't have to put this in front of any other functions?

Edited 5 Years Ago by l1ttledb: n/a

K guys, the function is good now thanks..

any ideas why it won't return the char?

{
char choice;

    printf(" Would you like the data sorted, Y or N:");
    scanf(" %c", &choice);
    return choice;
}

Edited 5 Years Ago by l1ttledb: n/a

Output the character before returning, see if it's being read properly.

And see this about your scanf()

edit: think its ok, how come i had to put char graphic_choice( char x ),...

Because you are defining the function as returning a character.

... i didn't have to put this in front of any other functions?

Because your compiler sloppily allows untyped functions to default to integer without warnings. Check your compiler settings and turn more warnings on.

Edited 5 Years Ago by WaltP: n/a

K guys, the function is good now thanks..

any ideas why it won't return the char?

{
char choice;

    printf(" Would you like the data sorted, Y or N:");
    scanf(" %c", &choice);
    return choice;
}

scanf(" %c",&choice) -> You have put a space infront of %c. that could be your problem. scanf is dirty. Avoid using it.

This article has been dead for over six months. Start a new discussion instead.