Xiang
04-01-2003, 01:25 PM
Dear sir,
Refers to the below coding. Do you know, where is my mistake, as after I enter an account number the program will stop and back to the source file. Why???
#include <stdio.h>
#include <conio.h>
void readinput (int i);
void writeoutput (int i);
struct date {
int month;
int day;
int year;
};
struct account {
char name[80];
char street[80];
char city[80];
long int acct_no;/* (positive integer) */
char acct_type;/* C (ccurent), O (overdue), or D (deliquent) */
float oldbalance;/* (nonnegative quantity) */
float newbalance;/* (nonnegative quantity) */
float payment;/* (nonnegative quantity) */
struct date lastpayment;
} customer[100];/* maintain as many as 100 customers */
void main(void)
{
int i, n;
clrscr();
printf("CUSTOMER BILLING SYSTEM\n\n");
printf("How many customers are there? ");
scanf("%d", &n);
for (i = 0; i < n; ++i)
{
readinput(i);
/* determine account status */
if (customer[i].payment > 0)
customer[i].acct_type = (customer[i].payment < 0.1 * customer[i].oldbalance) ? 'O' : 'C';
else
customer[i].acct_type = (customer[i].oldbalance > 0) ? 'D' : 'C';
/* adjust account balance */
customer[i].newbalance = customer[i].oldbalance - customer[i].payment;
};
for (i = 0; i < n; ++i)
writeoutput(i);
getch();
}
void readinput(int i)
/* read input data and update record for each customer */
{
printf("\nCustomer no. %d\n", i + 1);
printf(" Name: ");
scanf(" %[^\n]", customer[i].name);
fflush(stdin);
printf(" Street: ");
scanf(" %[^\n]", customer[i].street);
fflush(stdin);
printf(" City: ");
scanf(" %[^\n]", customer[i].city);
fflush(stdin);
printf(" Account number: ");
scanf("%ld", &customer[i].acct_no);
fflush(stdin);
printf(" Previous balance: ");
scanf("%f", &customer[i].oldbalance);
fflush(stdin);
printf(" Current payment: ");
scanf("%f", &customer[i].payment);
fflush(stdin);
printf(" Payment date (mm/dd/yyy): ");
scanf("%d/%d/%d", &customer[i].lastpayment.month,
&customer[i].lastpayment.day,
&customer[i].lastpayment.year);
return;
}
void writeoutput(int i)
/* display current information for each customer */
{
printf("\nName: %s", customer[i].name);
printf(" Account number: %d\n", customer[i].acct_no);
printf("Street: %s\n", customer[i].street);
printf("City %s\n\n", customer[i].city);
printf("Old balance: %7.2f", customer[i].oldbalance);
printf(" Current payment: %7.2f", customer[i].payment);
printf(" New balance: %7.2f\n\n", customer[i].newbalance);
printf("Account status: ");
switch (customer[i].acct_type)
{
case 'C' : printf("CURRENT\n\n");
break;
case 'O' : printf("OVERDUE\n\n");
break;
case 'D' : printf("DELINQUENT\n\n");
break;
default : printf("ERROR\n\n");
}
return;
}
Thanks,
Xiang
Refers to the below coding. Do you know, where is my mistake, as after I enter an account number the program will stop and back to the source file. Why???
#include <stdio.h>
#include <conio.h>
void readinput (int i);
void writeoutput (int i);
struct date {
int month;
int day;
int year;
};
struct account {
char name[80];
char street[80];
char city[80];
long int acct_no;/* (positive integer) */
char acct_type;/* C (ccurent), O (overdue), or D (deliquent) */
float oldbalance;/* (nonnegative quantity) */
float newbalance;/* (nonnegative quantity) */
float payment;/* (nonnegative quantity) */
struct date lastpayment;
} customer[100];/* maintain as many as 100 customers */
void main(void)
{
int i, n;
clrscr();
printf("CUSTOMER BILLING SYSTEM\n\n");
printf("How many customers are there? ");
scanf("%d", &n);
for (i = 0; i < n; ++i)
{
readinput(i);
/* determine account status */
if (customer[i].payment > 0)
customer[i].acct_type = (customer[i].payment < 0.1 * customer[i].oldbalance) ? 'O' : 'C';
else
customer[i].acct_type = (customer[i].oldbalance > 0) ? 'D' : 'C';
/* adjust account balance */
customer[i].newbalance = customer[i].oldbalance - customer[i].payment;
};
for (i = 0; i < n; ++i)
writeoutput(i);
getch();
}
void readinput(int i)
/* read input data and update record for each customer */
{
printf("\nCustomer no. %d\n", i + 1);
printf(" Name: ");
scanf(" %[^\n]", customer[i].name);
fflush(stdin);
printf(" Street: ");
scanf(" %[^\n]", customer[i].street);
fflush(stdin);
printf(" City: ");
scanf(" %[^\n]", customer[i].city);
fflush(stdin);
printf(" Account number: ");
scanf("%ld", &customer[i].acct_no);
fflush(stdin);
printf(" Previous balance: ");
scanf("%f", &customer[i].oldbalance);
fflush(stdin);
printf(" Current payment: ");
scanf("%f", &customer[i].payment);
fflush(stdin);
printf(" Payment date (mm/dd/yyy): ");
scanf("%d/%d/%d", &customer[i].lastpayment.month,
&customer[i].lastpayment.day,
&customer[i].lastpayment.year);
return;
}
void writeoutput(int i)
/* display current information for each customer */
{
printf("\nName: %s", customer[i].name);
printf(" Account number: %d\n", customer[i].acct_no);
printf("Street: %s\n", customer[i].street);
printf("City %s\n\n", customer[i].city);
printf("Old balance: %7.2f", customer[i].oldbalance);
printf(" Current payment: %7.2f", customer[i].payment);
printf(" New balance: %7.2f\n\n", customer[i].newbalance);
printf("Account status: ");
switch (customer[i].acct_type)
{
case 'C' : printf("CURRENT\n\n");
break;
case 'O' : printf("OVERDUE\n\n");
break;
case 'D' : printf("DELINQUENT\n\n");
break;
default : printf("ERROR\n\n");
}
return;
}
Thanks,
Xiang