Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-01-2003, 01:25 PM   PM User | #1
Xiang
New Coder

 
Join Date: Jul 2002
Location: Malaysia
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Xiang is an unknown quantity at this point
structure

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
Xiang is offline   Reply With Quote
Old 04-01-2003, 06:48 PM   PM User | #2
Shift4Sms
Regular Coder

 
Join Date: Jul 2002
Location: Las Vegas, NV - USA
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Shift4Sms is an unknown quantity at this point
I'm assuming that this is a simple test program, if not, scanf() is not very user friendly! Anyway, your immediate problem is that "n" is never set so the value is unknown.

Wait, strike that. I do see where you set "n". The next issue is that your loop "for(i=0; i<n; ++i)" should probably be "for(i=0; i<n; i++)" -- the difference between "++i" and "i++" is that the first value that "i<n" will see is 1 if the former is used.
__________________
Steven Sommers (blog)
Shift4 Corporation -- www.shift4.com

Creators of $$$ ON THE NET(tm) payment processing services.

Last edited by Shift4Sms; 04-01-2003 at 06:52 PM..
Shift4Sms is offline   Reply With Quote
Old 04-01-2003, 09:32 PM   PM User | #3
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
I don't see the problem, at least not yet. But there are two things Ive seen, one is that you have a ';' after one of te for() { } loops and then your date is mm/dd/yyy didn't get the 3y's but that is your code....still looking though. And I don't get why ++i and i++ are different never had a difference in them before.



Jason
Jason is offline   Reply With Quote
Old 04-02-2003, 12:00 AM   PM User | #4
djdante97
New Coder

 
Join Date: Dec 2002
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
djdante97 is an unknown quantity at this point
Quote:
Originally posted by Jason
And I don't get why ++i and i++ are different never had a difference in them before.
the difference is ++i is pre-increment, and i++ is post increment.
example:
Code:
int i, s, t;
i = 1;
s = i++; // s gets 1 since i is incremented post-operation
t = ++i; // t gets 3 since i is incremented pre-operation
djdante97 is offline   Reply With Quote
Old 04-02-2003, 11:23 AM   PM User | #5
Phantom
Regular Coder

 
Join Date: Feb 2003
Location: East Side/West Side
Posts: 118
Thanks: 0
Thanked 0 Times in 0 Posts
Phantom is an unknown quantity at this point
I think I've heard that explained as "++i increments i, then returns i; i++ returns i, then increments i"
Phantom is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:19 AM.


Advertisement
Log in to turn off these ads.