scanf help, returning incorrect value
Hi there,
I'm working on an assignment where I have to write a program that takes a user's order by prompting for customer number, for example:
Enter the customer number (0 to quit):
For each customer number entered displays the following menu to the user:
A - Enter weight of artichokes
B - Enter the weight of beets
C - Enter the weight of carrots
Q - Exit the ordering process for customer customerNumber
Enter option:
When the order for the customer is entered, the program has to compute the total charges, the discount, the shipping charges, and the grand total. The program should then display all the purchase information: the cost per kg, the kilograms ordered, and the cost for that order for each vegetable (if the vegetable was not ordered, then do not include it in the display), the total cost of the order, the discount (only if there is one), shipping weight, the shipping charge, and the grand total of all the charges.
The program will then prompt the user for the next customer number, until a customer number of 0 (zero) is entered. The program will then display the total weight of each vegetable ordered for all customers and the total sales of all shipments.
Now that you know what I'm up against, take pity on a poor noob and take a look at the first problem I'm having (I have a feeling I am slightly out of my league):
Code:
#include <stdio.h>
int getCustomer(int custNo);
int main(void)
{
int custNo;
getCustomer(custNo);
printf("Customer number: %d\n", custNo);
}
int getCustomer(int custNo)
{
printf("Enter the customer number (0 to quit):\n");
scanf("%d",&custNo);
while(custNo<0)
{
printf("Invalid customer number, please re-enter.");
scanf("%d\n", &custNo);
}
printf("Customer number accepted. Please proceed to order menu.\n");
return custNo;
}
This is set up just to test the output of the getCustomer function at the moment, and yet when I enter 1 as my customer number, the function returns a 2... what am I doing wrong?