ok so the idea behind this is i have a program where info is entered for an account number, a last name, and a balance and it is stored in a structure.
afterwards the info from the structure is suppose to be displayed in a formatted manner (as you can see in the code below), however i am only getting garbage numbers on the output. The account number is coming out random, the last name does not show at all, and the balance is coming out all zeroes.
Can anyone give me a pointer and what could be causing this? I made a program similar to this one a bit ago and it worked fine, and i am going mostly off that format, so im a bit lost on what i am missing here.
Any help is appreciated!
Code:
#include <stdio.h>
/* Define structure */
struct info
{
long int accntNum;
char name[25];
float balance;
};
/* Begin main */
main()
{
/* Declare variables */
struct info client[25];
int x, numClient;
/* Display opening message */
printf ("Welcome to Client Account Information Services\n\n");
/* Prompt for how many clients will have info entered */
printf ("Enter number of clients to be used: ");
scanf ("%i", &numClient);
/* Prompt for user to enter each clients info */
for (x = 0; x < numClient; x++)
{
printf ("\nEnter account number: ", x + 1);
scanf ("%ld", &client[x].accntNum);
fflush(stdin); /* Remove extraneous characters */
printf ("Enter last name: ", x + 1);
gets (client[x].name);
fflush(stdin); /* Remove extraneous characters */
printf ("Enter balance: ", x + 1);
scanf ("%f", &client[x].balance);
} /* end for */
/* Display each clients information */
printf ("\nACCOUNT LAST NAME BALANCE\n");
for (x = 0; x < numClient; x++);
{
printf ("\n%.4ld %s %.2f", client[x].accntNum, client[x].name, client[x].balance);
} /* end for */
return 0;
} /* end main */
and this is a sample of what my output looks like no matter how many clients i attempt to enter:
Code:
Welcome to Client Account Information Services
Enter number of clients to be used: 1
Enter account number: 100
Enter last name: smith
Enter balance: 300
ACCOUNT LAST NAME BALANCE
1245512 0.00Press any key to continue . . .