2016-12-05 2 views
1

Новое на C и собираюсь изучать его, чтобы я мог разработать сильные основы, поэтому решил зарегистрироваться здесь. Спасибо за помощь в продвинутом. Что не так с моим кодом - он падает на финальной строке printf()?Почему этот код сбой при запуске?

#include <stdio.h> 

main(int argc, char *argv[]) 
{ 
    // car loan calculator 
    int carPrice, carDownPayment, loanTerm; 
    float loanInterestRate, salesTax; 

    printf("What is the price of the car? "); 
    scanf("%d", &carPrice); 

    printf("How much down payment do you have? "); 
    scanf("%d", &carDownPayment); 

    printf("What is your loan's interest rate? "); 
    scanf("%f", &loanInterestRate); 

    printf("What is your sales tax? "); 
    scanf("%f", &salesTax); 

    printf("What is your loan term? "); 
    scanf("%d", loanTerm); 

    printf("The price of the car is %d. Your down payment is %d. Your loan interest rate is %1f. Sales tax is %2f. Your loan term is %d.", carPrice, carDownPayment, loanInterestRate, salesTax, loanTerm); 

    float monthlyPayment; 

    printf("Your monthly should be about %3.2f dollars over a term of %d months."), (carPrice * salesTax * loanInterestRate - carDownPayment/loanTerm), loanTerm; 

    return 0; 
} 
+0

Что случилось с вашим кодом? – Danh

+0

Сбой на линии, он пытается распечатать окончательный расчет. –

+0

'printf (« Ваш ежемесячный платеж должен составлять около 3,2 доллара США за срок в% d месяцев ». (CarPrice * salesTax * loanInterestRate - carDownPayment/loanTerm), creditTerm);' – Danh

ответ

3
  1. Scanf синтаксис ошибка в строке scanf("%d", loanTerm);
  2. Printf ошибка синтаксиса в рассогласования

    printf("Your monthly should be about %3.2f dollars over a term of %d months."), (carPrice * salesTax * loanInterestRate - carDownPayment/loanTerm), loanTerm;

    Подтяжки

`

#include <stdio.h> 

    int main(int argc, char *argv[]) 
    { 
    // car loan calculator 
    int carPrice, carDownPayment, loanTerm; 
    float loanInterestRate, salesTax; 
    float monthlyPayment; 

    printf("What is the price of the car? "); 
    scanf("%d", &carPrice); 

    printf("How much down payment do you have? "); 
    scanf("%d", &carDownPayment); 

    printf("What is your loan's interest rate? "); 
    scanf("%f", &loanInterestRate); 

    printf("What is your sales tax? "); 
    scanf("%f", &salesTax); 

    printf("What is your loan term? "); 
    scanf("%d", &loanTerm); 
    if(loanterm<=0){ 
    printf("Enter valid number \n");//can specify the range you want 
    return 0; 
    } 

    printf("The price of the car is %d.\nYour down payment is %d.\nYour loan interest rate is %1f.\nSales tax is %2f.\nYour loan term is %d.\n\n\n", carPrice, carDownPayment, loanInterestRate, salesTax, loanTerm); 



    printf("Your monthly should be about %3.2f dollars over a term of %d months.", ((carPrice + (carPrice * (salesTax/100)) + (carPrice * (loanInterestRate/100)) - carDownPayment)/loanTerm), loanTerm); 

    return 0; 
}` 
+0

Должна была действительно спать прошлой ночью. Пробовал узнать, как закодировать. Попытка выяснить следующие шаги, которые теперь (примерно), если (целое) для налога с продаж и процентной ставки кредита, затем конвертировать их в% путем перемещения десятичных точек. –

+0

Также исправлена ​​последняя печать. printf («Ваш ежемесячный платеж должен составлять около 3,2 доллара США в течение срока в% d месяцев». ((carPrice + (carPrice * salesTax) + (carPrice * loanInterestRate) - carDownPayment)/loanTerm), loanTerm); –

+0

@CharlesMullen Поздравляем, вы нашли его сами. –

0
#include <stdio.h> 

main(int argc, char *argv[]) 
{ 
// car loan calculator 
int carPrice, carDownPayment, loanTerm; 
float loanInterestRate, salesTax; 

printf("What is the price of the car? "); 
scanf("%d", &carPrice); 

printf("How much down payment do you have? "); 
scanf("%d", &carDownPayment); 

printf("What is your loan's interest rate? "); 
scanf("%f", &loanInterestRate); 

printf("What is your sales tax? "); 
scanf("%f", &salesTax); 

printf("What is your loan term? "); 
scanf("%d", &loanTerm); 

printf("The price of the car is %d.\nYour down payment is %d.\nYour loan interest rate is %1f.\nSales tax is %2f.\nYour loan term is %d.\n\n\n", carPrice, carDownPayment, loanInterestRate, salesTax, loanTerm); 

float monthlyPayment; 

printf("Your monthly should be about %3.2f dollars over a term of %d months.", ((carPrice + (carPrice * (salesTax/100)) + (carPrice * (loanInterestRate/100)) - carDownPayment)/loanTerm), loanTerm); 

return 0; 
} 
+1

Вы должны как минимум документировать сделанные изменения. Вы также должны подумать о принятии другого ответа. –

Смежные вопросы