Suppose savings and expenses are variables of type double that have been given values. Write an if-else statement that outputs the word Solvent, decreases the value of Savings by the value of expenses and sets the value of expenses to 0, provided that savings is more than expenses. If however, savings is less than expenses, the if-else statement simply outputs the word Bankrupt and does not change the value of any variable.
Specific question: Why does my program skip immediately through after I type in a value for savings? How can I remedy it?
#include <stdio.h>
void solvent();
int main(void)
{
double savings, expenses;
printf("\nEnter a number for savings: ");
scanf("%2lf", &savings);
printf("Enter a number for expenses: ");
scanf("%2lf", &expenses);
if(savings > expenses)
solvent();
else
printf("Bankrupt!");
system("pause");
return 0;
}
void solvent(double savings, double expenses)
{
printf("Solvent!");
savings -= expenses;
expenses = 0;
}