所以我想寫一個函數,接收一個浮點值,返回一個浮點值,並顯示在主要與printf。我不斷收到同樣的錯誤: markup2.c:58:錯誤:衝突的類型「用getPrice」 markup2.c:46:錯誤:「用getPrice」以前的隱式聲明在這裏我正在學習C,不知道爲什麼這是給我一個錯誤
我在哪裏做的錯誤?我嘗試過對所有接觸GetPrice的類型進行類型轉換,但仍然沒有運氣。有人能解釋我做錯了什麼嗎?
#include<stdio.h>
// define the constant MARKUP as float value 0.1
#define MARKUP 0.1
int main()
{
// declare variables
char proceed;
float value;
float markupValue;
// display welcome message to user and inform them of markup rate
printf("\nThank you for using Chad Hammond's markup calculator.\n");
printf("The current markup rate is %.1f%c.\n",MARKUP*100,'%');
// ask user if they want to perform a markup
printf("Would you like to markup an item? y/n:\n");
scanf("%c", &proceed);
// if yes, proceed to next step
if(proceed == 'y')
{
// prompt user for the price of item to be marked up
printf("Please enter a wholesale value to markup: ");
scanf("%f", &value);
// display input back to user
printf("The wholesale value you entered was: %c%.2f\n",'$', value);
markupValue = (value*MARKUP);
// display amount of increase
printf("The dollar amount of this increase will be: %c%.2f\n",'$', markupValue);
// display total price after increse
printf("The price for this item after markup is: %c%.2f\n",'$', (float)GetPrice(value));
}else
// if user did not want to markup an item, belittle them with sarcasm
printf("Well, if you didn't want to markup an item you should have just used a Ti-83 and left me alone!\n\n");
// display exit message
printf("Thank you for using HammondInstruments Markup Calculator, goodbye.\n");
// return that program has completed
return 0;
}
float GetPrice(float value)
{
float output;
value += value*MARKUP;
output = value;
return (float)output;
}
用'gcc -Wall -Wextra -o標記markup.c'進行編譯,你將看到錯誤:) – polslinux