Question
I'm throwing an error around where my function calcRetail is and it won't compile. Can someone please help? #include #include using namespace std; //Function prototype double calcRetail(double cost,double perc); int main() { //Declare variables double wholecost,retail,percent; //Input whole sale cost and validate as a correct number cout<<"Enter the whole sale cost: "; cin>>wholecost; while(wholecost<0){ cout<<"The number must be positive! "; cin>>wholecost; } //Input marked percentage and validate as a correct number cout<<"Enter the markup percentage: "; cin>>percent; while(percent<0){ cout<<"The number must be positive! "; cin>>percent; { //Call function to return retail price retail=calcRetail(wholecost,percent); //Output the retail cost cout<<"The retail cost is: $"<<fixed<<setprecision(2)<<retail<<endl; //Take a look at the screen system("PAUSE"); return 0; } //Function definition double calcRetail(double cost,double perc) { double retail; //calculate retail cost retail=cost+((cost*perc)/100); return retail; }
Explanation / Answer
First mistake You are including the class libraries properly, Proper way - #include Second You are giving enough parenthesis "{ }" Every '{' has to be closed by a '}' Also see that your // are in the correct place. I have modified the code , check once. #include //Function prototype double calcRetail(double cost,double perc); int main() { //Declare variables double wholecost,retail,percent; //Input whole sale cost and validate as a correct number coutwholecost; while(wholecost