Я пытаюсь запустить следующую программу, но он продолжает давать мне ошибки в конце ... кажется, что я забыл закрыть цикл или так .. если кто-то может помогите мне, что было бы здорово !!ошибка; ожидаемое выражение перед 'else'
#include <stdio.h>
#include <math.h>
main() {
//variables
int user_selection, count_donate=0, count_invest=0;
float balance_of_fund, donate_amt, invest_amt;
//input
printf("Welcome!\n");
printf("What is the initial balance of the fund?\n");
scanf("%f", balance_of_fund);
//provide user with options
printf("What would you like to do?\n 1 - Make a donation\n 2 - Make an investment\n 3 -
Print balance of fund\n 4 - Quit\n");
//work with user selectiom
scanf ("%d", user_selection);
if (user_selection > 0 && user_selection < 4) {
//ask for donation amount
for (user_selection = 1; user_selection<=1; user_selection++) {
printf("How much would you like to donate?\n");
scanf("%f", donate_amt);
balance_of_fund = balance_of_fund + donate_amt;
count_donate++;
}
//ask for investment amount
for (user_selection = 2; user_selection<=2; user_selection++) {
printf("How much would you like to invest?\n");
scanf ("%f", invest_amt);
balance_of_fund = balance_of_fund - invest_amt;
count_invest++;
}
//print out final balance for selection 3
for (user_selection = 3; user_selection<=3; user_selection++) {
printf("The final balance is $%.2f.", balance_of_fund);
printf("There were %d donations and %d investments.",count_donate, count_invest);
}
//Quit for selection 4
else if (user_selection = 4) {
printf("The final balance is $%.2f." ,balance_of_fund);
}
else {
printf("Please make a valid selection");
}
return 0;
если у вас есть какие-либо предложения, пожалуйста, дайте мне знать .. на данный момент я не уверен, что я делаю неправильно
Это не действует C++ в любом случае. Он нужен 'int main'. И я думаю, что вы ищете, это переключатель. – chris
Почему вы используете for-loops вместо простых if-statements (и да, переключатель будет еще лучше)? – Dukeling
причина, по которой im использует for-loops, потому что это было специально запрошено в этом согласии. – user2803386