I have just begun my intro to programming class, so please bear with me. When I set my precision I receive an error of something like: cannot convert bool to std; I know it's got something to do with my first function. I thought the result of the function was stored as an integer, but apparently that's not right. How can I alter the function, given my limited knowledge, so I can setprecision. Any suggestions would be greatly appreciated. Thanks.
Code:#include <iostream> #include <iomanip> using namespace std; int getQuantity (int); float totalCost (int, const float); int main() { const float PC_COST = 995.00; const float MEM_COST = 89.95; const float ZIP_COST = 99.99; const float PRINT_COST = 119.50; int numberPCs, numberMem, numberZip, numberPrint,pc_quantity; int mem_quantity, zip_quantity, print_quantity; float pc_total, mem_total, zip_total, print_total, totalOrder; cout<<"Enter the number of PC's:"; pc_quantity= getQuantity(numberPCs); cout<<"Enter the number of memory cards:"; mem_quantity= getQuantity(numberMem); cout<<"Enter the number of zip drives:"; zip_quantity= getQuantity(numberZip); cout<<"Enter the number of printers:"; print_quantity= getQuantity(numberPrint); cout<<"\n\n"; cout<<" New Wave Computer Company "<<endl; cout<<" ***********************************"<<endl; cout<<"Product"<<setw(25)<<" Cost each "<<setw(15)<<" Quantity " <<setw(15)<<" Total Cost "<<endl; cout<<"\n"; pc_total= totalCost (pc_quantity, PC_COST); mem_total= totalCost (mem_quantity, MEM_COST); zip_total= totalCost (zip_quantity, ZIP_COST); print_total= totalCost (print_quantity, PRINT_COST); cout<<setiosflags(ios::fixed||ios::showpoint)<<setprecision(2); cout<<"Personal Computers"<<setw(11)<<PC_COST<<setw(15)<<pc_quantity <<setw(15)<<pc_total<<endl<<endl; cout<<"Memory Cards "<<setw(11)<<MEM_COST<<setw(15)<<mem_quantity <<setw(15)<<mem_total<<endl<<endl; cout<<"Zip Drives "<<setw(11)<<ZIP_COST<<setw(15)<<zip_quantity <<setw(15)<<zip_total<<endl<<endl; cout<<"Printers "<<setw(11)<<PRINT_COST<<setw(15)<<print_quantity <<setw(15)<<print_total<<endl<<endl; totalOrder= pc_total + mem_total + zip_total + print_total; cout<<"Total Cost of Order"<<setw(40)<<totalOrder<<endl; return 0; } int getQuantity (int a) { int x; cin>>x; a=x; if (a >=0 && a <=100) return x; else return 0; } float totalCost (int b, const float a) { float totalCost = b * a; return totalCost; }



LinkBack URL
About LinkBacks


