我对 C 编程(以及一般情况下)是全新的,并且我被困在我的功能的一部分上。我正在尝试进行错误检查,但我不断收到错误
error: invalid operands to binary < (have 'float *' and 'double')
在第 97 和 100 行。这与我使用的数字类型有关吗?
下面粘贴的是我的完整代码
#include <stdio.h>
#include <stdlib.h>
// Function Declarations
void getData (float* startAmt, float* intRate, int* numYears, int* startYear);
void calcTaxes (float startAmt, float intRate, int numYears, int startYear, float* endAmt, float* intEarned, float* percentGained, int* finalYear);
void printResults (float startAmy, float intRate, int numYears, int startYear, float endAmt, float intEarned, float percentGained, int finalYear);
int main (void)
{
// Local Declarations
float startAmt;
float intRate;
int numYears;
int startYear;
float endAmt;
float intEarned;
float percentGained;
int finalYear;
// Statements
getData (&startAmt, &intRate, &numYears, &startYear);
calcTaxes ( startAmt, intRate, numYears, startYear, &endAmt, &intEarned, &percentGained, &finalYear);
printResults ( startAmt, intRate, numYears, startYear, endAmt, intEarned, percentGained, finalYear);
return 0;
}
//~~~~~~~~~~~~~~~ getData ~~~~~~~~~~~~~~~~~~~~
/*
* Function Name: getData
*
* Input Parameters: startAmt, intRate, numYears, startYear
*
* Description: This function reads compound interest data from the keyboard and stores it in the parameters using pointers
*
* Return Value: None
*/
void getData (float* startAmt, float* intRate, int* numYears, int* startYear)
{
// Statements
printf("\nCOP 2220 Project 2: Walter Doherty\n");
printf("\nEnter a Starting amount (dollars and cents): \n");
scanf ("%f", startAmt);
printf("Enter an Interest rate (ex. 2.5 for 2.5%): \n");
scanf ("%f", intRate);
printf("Enter the Number of years (integer number): \n");
scanf ("%d", numYears);
printf("Enter the Starting year (four digits): \n");
scanf ("%d", startYear);
// Validations
if (startAmt < .01)
exit("Starting amount must be at least one cent.\nExiting");
if (intRate < .001)
exit("Interest rate must be at least .1%.\nExiting");
if (numYears < 1)
exit("Number of years must be at least 1.\nExiting");
if (startYear < 999 ^ startYear > 10000)
exit("Year must be four digits\nExiting");
return;
}
我还收到有关我所有if
陈述的警告消息。它说warning: passing argument 1 of 'exit' makes integer from pointer without a cast [enabled by default]
我应该担心这个吗?Code::Blocks 不会将其记录为错误。谢谢 8)