just to clarify I started with exit, then went to continue then stopped refining it when I got to here.
Code:
int i, temp;
int account_number[10];
char last_name[10][30];
float account_balance[10];
printf ("Enter account number, last name, and balance.\n");
printf ("Enter -999 to end input.\n");
for (i = 0; i < 10; i++)
{
printf ("? ");
scanf ("%i", &account_number[i]);
if (account_number[i] == -999)
{
printf ("\n");
break;
}
if (account_number[i] < 1 || account_number[i] > 1000)
{
printf ("*** Invalid account number. Please enter 1 - 1000 or -999 to exit ***\n");
scanf ("%i", &account_number[i]);
i--;
}
scanf ("%s", last_name[i]);
scanf ("%f", &account_balance[i]);
if (account_balance[i] < 0)
{
printf ("*** Invalid balance amount. Please enter a positive value. ***\n");
scanf ("%f", &account_balance[i]);
i--;
}
} /* End for loop */
for (i = 0; i < 10; i++)
{
if (account_number[i] > account_number[i+1])
{
temp = account_number[i];
account_number[i] = account_number[i+1];
account_number[i+1] = temp;
}
}
though I do think I remember that to means to just quit and not print if -999 is also part of the equation. which this does not have, that is why I use an exit in the first place. kill program no chance of printing anything out logic
I think that was my code, I got two separate ones
this is the other one I know for sure, where I am not sure where I left off, I do remember putting in extra loops
for kicks , but the point is no more exit
Code:
#include <stdio.h>
#include <stdlib.h> // exit
#include <string.h> // strcpy
typedef int bool;
#define true 1
#define false 0
struct People
{
int account_number;
float account_balance;
char last_name[100]; // for them people that got
// really really long last names
};
bool compare(struct People s1,struct People s2)
{
return s1.account_number<s2.account_number;
}
struct People account[5];
int main (void)
{
int max_account = 0;
int account_num = 0;
char Lname[100];
float bal = 0.0;
while ( (max_account != 3 ) && ( account_num != -999) )
{
printf ("Enter account number, last name, and balance.\n");
printf ("Enter -999 to end input.\n");
printf ("? ");
// scanf ("%d", &account_num);
scanf("%d %s %f",&account_num, Lname, &bal);
// -999 just kill it or kick it back up to
// top of loop and it goes out of loop
if(max_account == 0 && account_num == -999)
{
//exit(0);
continue;
}
// check account number
else if ( (account_num < 1 || account_num > 1000 ) && account_num != -999)
{ printf("1 here\n");
//while (account_num < 1 || account_num > 1000)
do
{
printf("reenter your account number, or -999 to quit.\n");
scanf("%d", &account_num);
if (account_num == -999)
// exit(0);
continue;
} while (account_num < 1 || account_num > 1000);
}
else if ( account_num == -999)
//exit(0);
continue;
else
account[max_account].account_number = account_num;
// get the rest
printf("2 here\n");
// scanf("%s %f", Lname, &bal);
// copy in name
strcpy(account[max_account].last_name, Lname);
printf("account.name %s\n", account[max_account].last_name);
// printf("here 3\n");
// scanf("%f", &bal);
//check balance
if(bal < 0.0 )
{
while (bal < 0.0)
{
printf("reenter your balance\n"
"their is no way you're that broke\n"
"Come on. Go ask your mom for\n"
"for a dollar if you have to.\n");
scanf("%f", &bal);
}
}
// if everything is good for bal just assign it
account[max_account].account_balance = bal;
max_account += 1;
printf("max num %d\n", max_account);
printf("Good: %d %s %.02f\n", account_num, Lname, bal);
}// end control while loop
// sort code goes here/ work in progress
// sort and print code goes here
// protective if statment
// continue kicks it out of while loop and
// if no accounts created then do not even try to sort
// or print
// it just exits.
// could be over kill.. testing testing testing
// is needed still
if ( max_account >= 1 )
{
int j,i;
struct People temp;
for(i=1;i<max_account;i++)
{
for(j=0;j<max_account-i;j++)
{
if(account[j].account_number > account[j+1].account_number)
{
temp = account[j];
account[j] = account[j+1];
account[j+1] = temp;
}
}
}
for ( int a = 0; a < max_account; a++)
{
printf(" ACCOUNT LAST NAME BALANCE\n"
" %d %s %.02f\n",
account[a].account_number,
account[a].last_name,
account[a].account_balance);
}
} // end if
return 0;
} /* End main */
format for print out .. that is just user specs