初始化时无法将float float转换为float

时间:2017-10-21 00:44:57

标签: c++

我希望你们做得好!我在这里寻找关于我在C ++上无法弄清楚的错误的帮助。我是C ++的初学者和一般的新编码。这项任务将在晚上11:59进行,所以答案将非常感谢,并附有解释。谢谢大家!

错误:

在功能' int main()':  28:7:警告:未使用的变量" totalC' [-Wunused-variable]

在函数' float total_cost(int)': 66:13:错误:无法转换' float(*)(float)'到'漂浮'在初始化

代码:

#include <iostream>
#include <cmath> 
#include <iomanip>
using namespace std;

//Prototypes:
//Gives user instructions 
void instructions(); 
//Asks user for number of books being bought and downloaded
int prompt();
//Calculation for Sub total without discount 
float calcSubTotal(float);
//Calculation for Discount 
float calcDiscount(int);
//Calculation for Total Cost
float total_cost(int);
//Outputs results for user 
void label(); 



int main()
{
instructions();
int nb = prompt(); //save value of prompt as pR
float subT = calcSubTotal(nb); //save value of calcSubTotal as subT
float Disc = calcDiscount(subT); //save value of calcDiscount as Disc
float totalC = total_cost(Disc); //save value of total_cost as totalc
label(); 
return 0;
}

//Instructions  Function 
void instructions(){
cout << "***************************************************************************" << endl; 
cout << " Hello and welcome to BandN Book Store!" << endl; 
cout << " Each eBook costs $8.99." << endl; 
cout << " Today, we are having a special where you can get 15% off your total order. " << endl;
cout << "***************************************************************************" << endl; 
}

//Number of books Function 
int prompt(){
    float books;
    cout << "How many ebooks do you wish to download?" << endl; 
    cin >> books;
return books; 
}

//calcSubTotal Function 
float calcSubTotal(float books){
    float Price_per_book = 8.99; 
    float subTotal = books * Price_per_book;    
return subTotal; 
}

//Discount Function 
float calcDiscount(int Price_Totaldisc){
    float subTotal = Price_Totaldisc;
    float disc = 0.15;  
    float discount = subTotal * disc; 
    float discount_value = subTotal - discount;
return discount_value; 
}

//Total Cost Fucntion
float total_cost(int dis_val){ 
float sub = calcSubTotal; //ERROR
float dis_value = dis_val; 
float totalcost = sub - dis_value; 

    return totalcost; 
}

//Prints Out results 
void label (int nb, float, float subT, float disc, float totalC){ 

cout << "***************************************" << endl; 
    cout << "The number of ebooks downloaded: " << nb << endl; 
    cout << setprecision(4); 
    cout << "Sub-total: " << "$" << subT << endl; 
    cout << setprecision(4); 
    cout << "Discount: " << "$" << disc << endl; 
    cout << setprecision(4);
    cout << "Total cost: " << '$' <<  totalC << endl; 
    cout << "***************************************" << endl; 
} 

2 个答案:

答案 0 :(得分:0)

您在calcSubTotal电话中缺少参数。你需要写float sub = calcSubTotal(inbooks)

答案 1 :(得分:0)

从我所知道的,当它是一个函数名时,你就像一个变量一样编写calcSubTotal。你需要说

float sub = calcSubTotal(books);

你需要调用prompt()然后调用calcSubTotal(books)然后调用total_cost(dis_val) 我会在total_cost()

中定义一个浮点变量书和小计
float total_cost(int dis_val){ 
    float books = prompt();
    float subTotal = calcSubTotal(books);
    float sub = subTotal; //ERROR
    float dis_value = dis_val; 
    float totalcost = sub - dis_value; 

    return totalcost; 
}

修复后,您需要修复main函数内部的label()调用。我会让你这样做,但如果你需要任何帮助,我会:)