Markup program Feedback

hi im new at C++ program and i would like some feedback on how to make this better please here is my HW assignment

Markup:

Write a program that asks the user to enter an item's wholesale cost and it's markup percentage. It should then display the item's retail price. For example
* if an item's wholesale cost is $5.00 and its markup percentage is 100%, then the item's retail price is 10.00

* if an item's wholesale cost is $5.00 and its markup percentage is 50%, then the item's retail price is 7.50

The program should have a function name - calculateRetail - that receives the wholesale cost and the markup percentage as arguments, and return the retail price of the item.

*** Input Validation: Do not accept negative values for either the wholesale cost of the item or the markup percentage.***

i need help also on what to change the if statement into because my professor doesn't want me to use loop or the if statements in the main only main function consists of only function calls, but i need to keep the error messages since its part of the homework. also need help on where to put like void at cause i forget how or where to work it





#include <iostream>
#include <iomanip>

using namespace std;

double calculateRetail(double wholesaleCost, double markupPercent)
{

double retailPrice;
retailPrice = (wholesaleCost * markupPercent) + wholesaleCost;
return retailPrice;

}

int main()
{
double wholesaleCost;
double markupPercent;
double total;

double calculateRetail (double, double);

//Enter Wholesale Price
cout << "Enter wholesale Price: $";
cin >> wholesaleCost;

if( wholesaleCost < 0 )
{
cout << "Error invalid wholesale cost...Enter a postive number: $";
cin >> wholesaleCost;
}

//Enter Markup Percentage
cout << "Please Enter markup percent: ";
cin >> markupPercent;

if(markupPercent < 0)
{
cout << "Error invalid markup percentage...enter a postive number ";
cin >> markupPercent;
}

markupPercent = markupPercent * .01;

//This is the function call
total = calculateRetail(wholesaleCost, markupPercent);

cout << fixed << setprecision(2);
cout << "The retail price is $" << total << endl;
cout << endl;

system ("pause");
return 0;
}
void goes in place of a return value. I don't think you need it here.
Put the pre-conditions in the function calculateRetail. Also don't declare the function header calculateRetail inside of main (another function.) In fact, here you don't need to declared the function header at all.
think of the program as a tree. you start at the trunk and move up. so you call your first function which would request the variables, than you need to calculate the total. so make another function for that. then output the value in before you close the first function or in a new function, depending on what you want. also, removing the system pause is a great idea and define your functions like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

int addition(int i, int j); 

int main(){
std::cout << addition(1,2);
std::cin.ignore(); //possible replacement for system("pause");
return 0;
}

int addition(int i, int j){
return i+j;
}


this is the standard way of doing functions and comes with several benefits such as easier function referencing within functions(you will see if you make a program with alot of functions and see that some of the function references do not work and you get an undeclared error, this is because the function is declared before defining the function, remember scope of declaration or whatever your teacher called it. doing it this way defines the function and then executed the functions after all the definitions have been executed so that the function is always declared before you reference it.)
none of these helped me sorry this is what i got please some one help me so confused and now im getting errors that wont run the program

#include <iostream>
#include <iomanip>

using namespace std;

//Function Prototypes
int getwholesaleCost();
double calculateRetail (double wholesaleCost, double markupPercent);
double retailPrice;
double calculateRetail (double, double);
void display(double total);

int main()
{
double wholesaleCost;
double markupPercent;
retailPrice = (wholesaleCost * markupPercent) + wholesaleCost;

system ("pause");
return 0;
}

// function declarations

// Function - Entering a Wholesales price that doesnt included a negative number
int getwholesaleCost()
{
int wholesaleCost; // local variable

cout << "Enter wholesale Price: $";
cin >> wholesaleCost;


//Error Message when entering in a negative number
while(wholesaleCost < 0 )
{
cout << "Error invalid wholesale cost...Enter a postive number: $";
cin >> wholesaleCost;

}// end getwholesale
return wholesaleCost;
}
int markupPercent()
{
//Function - Entering a Markup Percent to see how much percent was taken off
cout << "Enter The Markup Percent: ";
cin >> markupPercent;

//Error Message when enter a number that is not positive
while(markupPercent < 0)
{
cout << "Error invalid markup percentage...enter a postive number ";
cin >> markupPercent;
}


}//End Percentage

//Function Displaying the Total Retail Price
void display(double total)
{
cout << fixed << setprecision(2);
cout << "The retail price is $" << endl;


} // display
Format your code so we can quote by line numbers then.
this is my version of my program:

#include<iostream> //headers
#include<iomanip>

using namespace std;
//calculatedRetail function prototype
double calculatedRetail (double cost, double markUp);

int main()
{
double retail, cost, markUp; //variables set to double data type

cout<<fixed<<showpoint<<setprecision(2); //set outformat for retail price

cout<<"Enter the wholesale cost for the item: $";
cin >>cost;
//validate the cost price
while (cost<0)
{
cout<<"Please enter a positive number. $"<<endl;
cin >>cost;
}

cout<<"Now please enter its markup percentage: ";
cin >>markUp;
//validate the markup percentage
while (markUp<0)
{
cout<<"Please enter a positive number for markup: ";
cin >>markUp;
}
//convert markup percentage to two decimal point
markUp = (markUp/100);

/*************************************************
*****Call calculatedRetail fuction to calculate***
******************retail price********************
*************************************************/

cout<<"The retail price for the item is: "<<endl;
cout<<"$ " <<calculatedRetail(cost, markUp)<<endl;

return 0;
}
double calculatedRetail (double cost, double markUp)
{
return (cost*markUp)+cost; //calculate retail price and return value to main fuction
}


Last edited on
code tags please.
Topic archived. No new replies allowed.