Computing.Net > Forums > Programming > C++ Help (Simple..I think!)

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

C++ Help (Simple..I think!)

Reply to Message Icon

Original Message
Name: SteveG
Date: November 25, 2002 at 12:26:06 Pacific
Subject: C++ Help (Simple..I think!)
OS: WinXP
CPU/Ram: 880Mz 32Mb
Comment:

I've done the following program:

//////////////////////////////////////////////

#include
using namespace std;

void DisplayWelcome();
void GetItemData(double& cost, int& turnover);
double RetailCost(double cost,int turnover);

int main()

{
DisplayWelcome();
return 0;
int turnover;
double cost;
GetItemData(cost, turnover);
if (turnover<7) return (double(cost)+(0.05*double(cost)));
return (double(cost)+(0.15*double(cost)));

}

//**************************************************************************************
void DisplayWelcome()

{
cout << "This program determines the retail price for an item at Betta-Buy supermarket. " << endl;

}


//**************************************************************************************

double RetailCost(double double1,int int1)

{
cout << "Retail cost: " << RetailCost(double1,int1) << endl;
return 0;
}

I need to write and test a function DisplayCosts() that displays the Retail Cost, Wholesale Cost and Turnover for an Item. I think I need to work out the information needed for this function, and hence the number and type of parameters.

Any help appreciated.




Report Offensive Message For Removal


Response Number 1
Name: kev
Date: November 25, 2002 at 14:55:45 Pacific
Reply: (edit)

Well, I'm not really quite sure what you're asking for the DisplayCosts() function, but I think you made a few mistakes with what you already have up there:

1.) First of all, get rid of that return 0; on the 2nd line of your main function. That'll cause your program to quit right after the DisplayWelcome() function is done.

2.) You need to write the GetItemData(); function.

3.) I don't think you meant your RetailCost() function to be recursive. In the cout statement, you're calling the RetailCost function again. So, in essence, that function is a never-ending loop.

4.) The if statement in your main function shouldn't (in your case) return anything. Try something like:

if(turnover < 7)
retailcost = (1.05 * cost); //this will add 5 percent tax
else
retailcost = (1.15 * cost); //this will add 15 percent tax

You need to create a new double variable for the retail cost, I just chose "retailcost".

Hope this helps!

Kevin.


Report Offensive Follow Up For Removal

Response Number 2
Name: kev
Date: November 25, 2002 at 15:31:12 Pacific
Reply: (edit)

Would this work?

void DisplayCosts(double retailcost, double cost, int turnover)
{
cout << "Wholesale cost: $" << cost << endl;
cout << "Retail cost: $" << retailcost << endl;
cout << "Turnover: " << turnover << endl;
}

Kevin.


Report Offensive Follow Up For Removal

Response Number 3
Name: SteveG
Date: November 26, 2002 at 02:09:14 Pacific
Reply: (edit)

The retail value should return a value. And if I remove the 'return 0;' statement, it has a error saying:

void __cdecl GetItemData(double &,int &)" (?GetItemData@@YAXAANAAH@Z)


Report Offensive Follow Up For Removal

Response Number 4
Name: kev
Date: November 26, 2002 at 14:11:58 Pacific
Reply: (edit)

Okay, for this case, return() statements only return a value from a funtion. If somewhere in your program you have to have a "return(retailcost);" statement, then you need to make a function that has that if statement in it, and then return the retail cost. Try this for the RetailCost(); function:

double RetailCost(double cost, int turnover)
{
if(turnover must get rid of that "return 0;" statement. Otherwise, like I said, your program will exit just after the DisplayWelcome() function is done.

If you're recieving that error, then it probably means that you have either not declared the GetItemData() function, or you have not wrote the GetItemData() function. Or, you may have declared it differently than what you wrote it. Like, maybe you declared GetItemData(double &cost, int &turnover); at the top, but when you actually write out what the function does at the bottom, you may have put just GetItemData(); with nothing in the parenthesis. They both have to be the same thing.

That probably was just a huge ramble about nothing, so if it still doesn't work, you can email me the code, and I'll try to fix it up.

Kevin.


Report Offensive Follow Up For Removal

Response Number 5
Name: kev
Date: November 26, 2002 at 14:15:18 Pacific
Reply: (edit)

Sorry, my last post got messed up...

Okay, for this case, return() statements only return a value from a funtion. If somewhere in your program you have to have a "return(retailcost);" statement, then you need to make a function that has that if statement in it, and then return the retail cost. Try this for the RetailCost(); function:

double RetailCost(double cost, int turnover)
{
if(turnover < 7)
return(1.05 * cost); //this will return retailcost + tax
else
return(1.15 * cost); //this will return retailcost + tax
}


You must get rid of that "return 0;" statement. Otherwise, like I said, your program will exit just after the DisplayWelcome() function is done.

If you're recieving that error, then it probably means that you have either not declared the GetItemData() function, or you have not wrote the GetItemData() function. Or, you may have declared it differently than what you wrote it. Like, maybe you declared GetItemData(double &cost, int &turnover); at the top, but when you actually write out what the function does at the bottom, you may have put just GetItemData(); with nothing in the parenthesis. They both have to be the same thing.

That probably was just a huge ramble about nothing, so if it still doesn't work, you can email me the code, and I'll try to fix it up.

Kevin.


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you own an iPhone?

Yes
No, but soon
No


View Results

Poll Finishes In 7 Days.
Discuss in The Lounge
Poll History




Data Recovery Software