I am attempting to build a basic C program that will determinewhether or not a p
ID: 3611870 • Letter: I
Question
I am attempting to build a basic C program that will determinewhether or not a person is over their credit limit. I am newat learning C so this may be a beginners mistake. When thecode executes, the results of the if statement appears of thescreen for a microsecond and then the program closes. Also,how would I make the program so that once it executes it enables auser to perform the same task again? Below is the code that Iwrote:#include <stdio.h>
int main(void)
{
int account; /* account number to be inputby user */
int begin; /* beginning balance to beinput by user */
int charges; /* charges to be input byuser */
int credits; /* credits to be input byuser */
int limit; /* credit limit to be input byuser */
int balance; /* variable in which totalbalance will be computed */
printf( "Enter account number (-1 toend): "); /* prompt */
scanf( "%d", &account); /* readsaccount number */
printf( "Enter beginning balance: "); /* prompt */
scanf( "%d", &begin); /* reads beginning balance */
printf( "Enter total charges: "); /* prompt*/
scanf( "%d", &charges); /* readscharges input */
printf( "Enter total credits: "); /* prompt*/
scanf( "%d", &credits); /* readsany credits */
printf( "Enter credit limit: "); /* prompt */
scanf( "%d", &limit); /* reads credit limit input */
balance = begin + charges - credits; /* assignstotal calculated to balance */
if ( balance > limit ){ /* exceedsbalance */
printf( "Account: %d ", account);
printf( "Credit limit: %d ", limit);
printf( "Balance: %d ", balance);
printf( "Credit Limit Exceeded ");
}
else {
printf( "Account in good standing ");
}
return 0;
} /* end function main */
Explanation / Answer
Dear One use system ( "pause" ); at the end of your code but before thereturn 0 statement; use do while tool strutcute in your code to repeat youractions or statements regardsRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.