-
Adding?
Hey I'm working on this program and the last thing I need to do is in case 3, adding how many investments would be made and how many donations would have been made. How do I do that?
Code:
int main(void)
{
int initial_balance=0, choice=0, donation=0, invest=0, fund=0, balance=0, total_donation, total_invest;
printf("Welcome!\n");
printf("\nWhat is the inital balance of the fund?\n");
scanf("%d", &initial_balance);
fund = initial_balance;
printf("What would you like to do?\n");
printf("\t1 - Make a donation\n");
printf("\t2 - Make an investment\n");
printf("\t3 - Print balance of fund\n");
printf("\t4 - Quit\n");
scanf("%d", &choice);
while(choice != 4)
{
switch(choice) {
case 1:
printf("How much would you like to donate?\n");
scanf("%d", &donation);
break;
case 2:
printf("How much would you like to invest?\n");
scanf("%d", &invest);
if (invest > donation)
printf("You cannot make an investment larger than the funds.\n");
fund = invest - initial_balance;
break;
case 3:
balance=initial_balance+donation-invest;
printf("\nThe current balance of the fund is $%.2d.\n", balance);
total_donation = donation;
total_invest = invest;
printf("There have been %.l donations and %.l investments.\n", total_donation,total_invest);
break;
default:
printf("You made an invalid selection.\n");
break;
}//end switch
printf("What would you like to do?\n");
printf("\t1 - Make a donation\n");
printf("\t2 - Make an investment\n");
printf("\t3 - Print balance of fund\n");
printf("\t4 - Quit\n");
scanf("%d", &choice);
}//end while
-
Can you provide an example of how case 3 should be working? I mean, what is the input? The output?
-
Heres what a sample run should be...
Welcome!
What is the initial balance of the fund?
15000
What would you like to do?
1 - Make a donation
2 - Make an investment
3 - Print balance of fund
4 - Quit
1
How much would you like to donate?
1000
What would you like to do?
1 - Make a donation
2 - Make an investment
3 - Print balance of fund
4 - Quit
2
How much would you like to invest?
2000
You cannot make an investment of that amount.
What would you like to do?
1 - Make a donation
2 - Make an investment
3 - Print balance of fund
4 - Quit
2
How much would you like to invest?
500
What would you like to do?
1 - Make a donation
2 - Make an investment
3 - Print balance of fund
4 - Quit
3
The current balance is $15500.00.
There have been 1 donations and 1 investments. <~~~ This is where I'm not sure as how to get.
-
Investments take money away? Why can't you invest larger then the amount you donated? This is very strange, please provide the complete ruleset.
Or do "investments" mean that you're removing money from the fund? (that sort of appears to be the intent?)
-
Yes you are correct about the investments. These are the what the option choices are.
Option 1:
Prompt the user for their donation amount. Add this amount to the balance of the fund.
Option 2:
Prompt the user for their investment amount. In order to continue to provide scholarships, the fund cannot be allowed to fall below its initial amount. If an investment would bring the fund below that value, then simply print out “You cannot make an investment of that amount.” If the amount is valid, deduct it from the balance of the fund.
Option 3:
Print the current balance of the fund, the current total number of donations, and the current total number of investments.
After options 1, 2, and 3 prompt the user with the menu again.
Option 4:
Print the final balance of the fund, the final total number of donations, and the final total number of investments.
-
something like
Code:
int number_of_donations_made = 0
...
case 3:
number_of_donations_made++;