C Source Code Help

RazorJack
01-18-2004, 04:57 PM
Writing an ANSI C program in linux for an assignment at school. Very simple program with a simple algorithm.

I've never written in C before, but used PHP, Perl, Basic, and just about everyother language besides C. :(

The problem im having is with the scanf() function.
When I put two scanf statements collecting data one after another, the second is skipped completely.


printf("\nEnter input: ");
scanf("%f", fltInput);
printf("\nEnter more input: ");
scanf("%f", fltInput2);


No errors are generated on compile.

Bohica
01-18-2004, 05:07 PM
Paste the whole thing, if you could.

Bohica
01-18-2004, 05:11 PM
Oh, also. Scanf takes a pointer to the data item you want to read into... so you'd need to do:

scanf("%f", &fltInput);
scanf("%f", &fltInput2);

RazorJack
01-19-2004, 03:30 PM
<stdio.h>
<math.h>

/* Declare the variables: */
/* Customer Number - input from user */
long int intCustomerNumber;

/* Water Meter and Previous Water Meter Level - input from user */
float fltMeterLevel;
float fltPrevMeterLevel;

/* Calculated Water Bill and Fixed Rate */
int intWaterBillAmount, intPercentage;
int FixedRate = 27.00;

/* Lets start! */
int main() {
/* get customers number */
printf("\nPlease enter the customer's number: ");
scanf("%l", &intCustomerNumber);

/* get current water level */
printf("\nEnter the current water level: ");
scanf("%f", &fltMeterLevel);

printf("\nEnter the previous months water level: ");
scanf("%f", &fltPrevMeterLevel);

/* Calculate the Percentage of Total Bill by Meter Level */
if (fltMeterLevel<=20000) {
intPercentage = 0;
} else if (fltMeterLevel<=50000) {
intPercentage = 10;
} else if (fltMeterLevel<=100000) {
intPercentage = 30;
} else if (fltMeterLevel > 100000) {
intPercentage = 60;
} else {
/* Validate Input */
printf("\nYou have entered an invalid amount.\n");
printf("Program will not quit.\n");
return 0;
}

/* Calculate and Print Bill */
intWaterBillAmount = FixedRate + ((fltMeterLevel-fltPrevMeterLevel)/1000) + (fltMeterLevel * (intPercentage/100));
printf("%d", intWaterBillAmount);
}
/* EOF! (Phew!) */