Greetings,
I am supposed to make it so when a user inputs 0, it would stop prompting for entries but I'm having difficulties using the while() statements. I tried using an if statement but it failed. Also I can't figure out how to add or subtract entries from the original balance for the Total Balance at the end.
I'm sure there are errors too.
Code:
#include <stdio.h>
int main() {
int number, sum=0, subtraction=0;
puts("---------- Welcome to Your Checkbook! ----------");
puts("Please enter your starting balance:");
scanf("%d", &number);
puts("Got it. Now enter each of your transactions");
puts("Positive number = deposit; Negative number = withdrawal; 0 to stop");
{(number == 0)? break;
puts("Enter your transaction:");
scanf("%d", &number);
sum += number;
if(number<0)
subtraction += number;
puts("Enter your transaction:");
scanf("%d", &number);
sum += number;
if(number<0)
subtraction += number;
puts("Enter your transaction:");
scanf("%d", &number);
sum += number;
if(number<0)
subtraction += number;
puts("Enter your transaction:");
scanf("%d", &number);
sum += number;
if(number<0)
subtraction += number;
puts("Enter your transaction:");
scanf("%d", &number);
sum += number;
if(number<0)
subtraction += number;
puts("Enter your transaction:");
scanf("%d", &number);
sum += number;
if(number<0)
subtraction += number;
puts("Enter your transaction:");
scanf("%d", &number);
sum += number;
if(number<0)
subtraction += number;
}
puts("Here is a summary of your account transactions:");
printf("Total deposits: $%d\n", sum);
printf("Total withdrawals: $%d\n", subtraction);
printf("Final balance is $%d\n", sum);
if(sum<0)
puts("Please note that your final balance is NEGATIVE");
}