I need help figuring out how to get this to calculate and print the number of times the investment and donate run. I've gotten everything else to run right just hit a road block with that one little part.
Code:
//Pre-processor
#include <stdio.h>
//Main Function
int main(){
//Variable declaration
int type,num_donate , num_invest;
float total, initial_balance, donate, invest, new_balance,t1,t2;
printf("Welcome!\n");
//user input
printf("What is the initial balance of the fund?\n");
new_balance += initial_balance;
scanf("%f", &initial_balance);
//print menu for user
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");
printf("Which would you like to do?\n");
scanf("%d", &type);
// continue until user inputs 4 to quit
while(type != 4){
switch (type){
//Donation case
case 1:
printf("How much would you like to donate?\n");
scanf("%f", &donate);
t1=donate + t1;
break;
//Investment case
case 2:
printf("How much would you like to invest?\n");
scanf("%f", &invest);
if(invest > donate)
printf("You cannot make an investment of that amount\n");
else
t2=invest - 2;
break;
//Balance case
case 3:
printf("The current balance is %.2f\n", t1 + initial_balance - t2);
printf("There have been %d donations and %d investments\n", num_donate, num_invest);
total+= t1;
case 4:
break;
default:
printf("Sorry that was not a vaild option\n");
break;
}//end switch
//reprint menu
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");
printf("Which would you like to do?\n");
scanf("%d", &type);
}
//end loop
printf("The final balance is %.2f\n",total=t1 + initial_balance - t2);
printf("There were %d donations and %d investments\n",num_donate, num_invest);
//end main function
return 0;
}