gpt4 book ai didi

c - 我做错了什么错误: invalid operands to binary * (have 'float *' and 'int' )|

转载 作者:行者123 更新时间:2023-11-30 20:36:28 25 4
gpt4 key购买 nike

我不断收到相同的错误消息,但不知道如何纠正

  /*This program will prospective borrowers calculate monthly payment on a loan.
The program also prints the amortization table to show the balance of the loan after each monthly payment.
By: Kenneth Moore
Date: 3/13/2016
*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>>

const float monthInYear = 12; //This is a constant for the number of months in a year
const float percentTotal = 100; //This is a constant for calculating percentages

void getData (float* prPtr, float* nyPtr, float* iyPtr);

//this function will calculate the data for monthly payments based off APR and return the data to be printed on a table
float calculateMonthlyPayment (float* nmPtr, float* imPtr, float* pPtr, float* qPtr, float* mpPtr, float* nyPtr, float* iyPtr, float* prPtr);
//This function will print the data
void printInformation ();
//This function will display information in a table format
void printAmortizationTable ();

int main()
{
float nm; //scheduled number of months for the loan
float ny; //scheduled number of years to amortize the loan
float iy; //interest rate per year as a percentage
float im; //interest rate/month decimal
float pr; //principal the amount of the loan
float p; //the value of (1+IM)
float q; //the value of P/(P-1)
float mp; //Monthly payment

printf("Welcome the following program will help you decide how much loan you can afford.");
printf("You will be prompted to enter the principle amount of the loan, the interest");
printf("rate, and the length of the loan in years. It will then show you on a table");
printf("how much your monthly payment will be and how much of the loan remains after");
printf("each payment.");

getData (&pr, &ny, &iy);
calculateMonthlyPayment(&nm, &im, &p, &q, &mp, &ny, &iy, &pr);
return 0;
}

/*This function is a data collecting function the will collect user imputed data about the loan and calculate the interest and
payments to be printed in later functions*/
//Statement
void getData (float* prPtr, float* nyPtr, float* iyPtr)
{
printf("\nEnter the amount of money you wish to borrow.");
scanf("%f", prPtr);
printf("Enter the length in years for the loan.");
scanf("%f", nyPtr);
printf("Enter your expected interest rate.");
scanf("%f", iyPtr);
return;
}

//This function will now process the data to return the payment amount to be used in the table
float calculateMonthlyPayment (float* nmPtr, float* imPtr, float* pPtr, float* qPtr, float* mpPtr, float* nyPtr, float* iyPtr, float* prPtr)
{
nmPtr =(nyPtr*12); //how many months the loan will be in effect
imPtr =(iyPtr/monthInYear)/percentTotal; //how much interest is paid per month
//this is my error location how can i reslove it

pPtr = pow(1+imPtr,nmPtr);
qPtr = pPtr/(pPtr-1);
mpPtr = (prPtr*imPtr*qPtr);
}

最佳答案

您将一个指针与一个常量相乘。我认为您想要指针指向的值。使用指针取消引用运算符 * (对于 nmPtr 也是如此,顺便说一下该函数中的其他指针):

*nmPtr =(*nyPtr*12);

关于c - 我做错了什么错误: invalid operands to binary * (have 'float *' and 'int' )|,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35972913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com