-3

When I try submitting my code to my prof, I get a compilation error with the following message:

ipc_ms1.c: In function ‘getDbl’: ipc_ms1.c:146:1: warning: control reaches end of non-void function [-Wreturn-type] ipc_ms1.c: In function ‘getInt’: ipc_ms1.c:122:1: warning: control reaches end of non-void function [-Wreturn-type]

I'm not sure what to do

#include <stdio.h>

void welcome(void);
int getInt(void);
double getDbl(void);
void prnTitle(void);
void prnFooter(double gTotal);
void pause(void);
double getDblLimited(double lowerLimit, double upperLimit);

void welcome(void)
{
printf("---=== Grocery Inventory System ===---\n");

}

void prnTitle(void)
{
printf("Row |SKU| Name \t | Price |Taxed| Qty | Min |  Total  |Atn \n");
printf("----+---+--------------------+--------+-----+-----+-----+------------+|---\n");

}
void prnFooter(double gTotal)
{
printf("--------------------------------------------------------+-----------  ------\n");
//float  gTotal = 1234.57;
while (gTotal > 0)
{
    printf("%12.21f", gTotal);
}
}
void clrKyb(void)
{
char b;
while (b != '\n')
{
    scanf("%c", &b);
}

}
 void pause(void)
{
printf("Press <Enter> to continue...");

clrKyb();

}
int getInt(void)
{
printf("Enter an interger:");
int d;
char c;
scanf("%d%c", &d, &c);
while (c != '\n')
{
    printf("Invalid integer, please try again ");
    scanf("%d%c", &d, &c);
}
}
int getIntLimited(int lowerLimit, int upperLimit)
{
int a;
printf("Enter an integer between %d and %d:", lowerLimit, upperLimit);
scanf("%d", &a);
while (a <= lowerLimit || a >= upperLimit)
{
    printf("Invalid value, %d < value < %d:", lowerLimit, upperLimit);
    scanf("%d", &a);
}
return a;
}
double getDbl(void)
{
double d;
char c;
printf("Enter a floating point number:");
scanf("%lf,%c", &d, &c);
while (c != '\n')
{
    printf("Invalid number, please try again ");
    scanf("%lf%c", &d, &c);
}

}

double getDblLimited(double lowerLimit, double upperLimit)
{
double a;
printf("Enter a floating point number between %f and %f:", lowerLimit,   upperLimit);
scanf("%lf", &a);
while (a <= lowerLimit || a >= upperLimit)
{
    printf("Invalid value, %f < value < %f:", lowerLimit, upperLimit);
    scanf("%lf", &a);
}
return a;
return 0;
}
J. Chomel
  • 8,193
  • 15
  • 41
  • 69
ortz3
  • 11
  • 4
  • where's `main` function ?? – artm Oct 30 '16 at 01:24
  • this is a 6 part project and for this part of the submission we were told to not include the main function – ortz3 Oct 30 '16 at 01:25
  • 2
    Please (doc-)comment and format your source code properly. Don't write and _never present uncommented code_. Ponder why it doesn't complain about `int getInt(void)` (or does it? How about `double getDblLimited()`?). (Those repeated `scanf()`-calls per `getType()` should be avoided.) – greybeard Oct 30 '16 at 08:07
  • indent your code properly – phuclv Nov 02 '16 at 07:25
  • You need to get in the habit of [accepting answers](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) which help you to solve your issues. You'll earn points and others will be encouraged to help you. – Jay Blanchard May 30 '17 at 18:18

2 Answers2

1

You forgot to return anything from getDbl.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
0

These are only warnings; says that function getDbl reaches the end of its implementation without returning anything. But it shows you don't realy know what you're doing. Follow Jonathan advice and find a good book.

I'll explain the warning:

Since it declared double <function_name>(<param_list>) it means you have a return statement to add at the end:

getDbl

double getDbl(void) {
  double d;
  char c;
  printf("Enter a floating point number:");
  scanf("%lf,%c", &d, &c);
  while (c != '\n') {
    printf("Invalid number, please try again ");
    scanf("%lf%c", &d, &c);
  }
  return d;
}

getInt

int getInt(void) {
  printf("Enter an interger:");
  int d;
  char c;
  scanf("%d%c", &d, &c);
  while (c != '\n') {
    printf("Invalid integer, please try again ");
    scanf("%d%c", &d, &c);
  }
  return d;
}

(and see how to format your code properly)

Community
  • 1
  • 1
J. Chomel
  • 8,193
  • 15
  • 41
  • 69