Hi I have been trying to get this code for about a week now its due shortly and I still can't get it. The instructions are to
1.Write a structure definition Sneakers that records a one character code fot the manufacture (N for Nike, R for Reebock, ect), an interger product code and the price of the pair of sneakers.
2. A funtion to enter data.
3. A fuction that calculates a sale price that has a 10% discount on the current price.
4. A function that passes the array of sneakers as an array parameter and displays all information about each pair of sneakers.
5. a.)write the main program which declares inventory as an array of sneakers of an arbitrary size.
b.)write a look that allows the stock clerk to enter info for as long as they want.
c.)For each item in the inventory call the Discount fuction to calculate the sale price.
d.)Add a switch statement that will translate the single letter code for the company to full name of output.
e.)write the final inventory with original price and sale price to a text file in the form of a chart.

Here is what I have so far:

#include<iostream>
using namespace std;
 
struct sneakers
{
     char letter;
     int code;
     double price;
};
 
void GetInfo(sneakers info[]);//Get info from keyboard
double saleprice(double price);//Calculate discounted price
 
int main()
{ 
sneakers inventory [100];
double sales,price,sale;
 
GetInfo(inventory);
 
sales=saleprice(price);
cout<<"The sale price of the sneaker is "<<sale<<" ";
 
char wait;
cout<<"Hit any key to end.";
cin>>wait;
 
void GetInfo(sneakers info[])
{
int i=0;
char contin='y';
while (contin=='y'||contin=='Y')
{
cout<<"Enter letter for manufacture";
cin>>info[i].letter;
cout<<"Enter product code";
cin>>info[i].code;
cout<<"Enter sneaker price";
cin>>info[i].price;
cout<<"Do you want to continue (y/n)";
cin>>contin;
i++;//I know I need to count the i's to see how large the size of array is but I don't know how to do that either.
}
return;
}
double saleprice(double price)
{
double sale;
sale=price-.10*price;
return sale;
}

Please help!!!!!!!!!!!!!!!!!!!!!!!!!!

What exactly is the problem you're having? Unfortunately, "please help" does not give us enough information to actually help.

That said, a few observations:
- you're missing the closing brace ('}') for main()
- when you pass the array to GetInfo, you should also pass the size of the array as a second parameter, so that you can avoid overflowing your array. While this doesn't allow the user to input data "as long as they want," it does keep your program from crashing in the event that they want to input more than you expect.
- for saleprice(), you can just return price * 0.9 .
- just looking at the instructions again, you should probably rename GetInfo to InputData or somesuch, since you also need a function to print the information contained in the array.

Just a li'l feedback for now, but specify a problem and we'll see about fixing it... ;)

PS - please use [ code] tags when you post your code, as it makes it a lot easier to read...

Hi everyone. I just started with this code. I don't understand how to use structures and arrays together. I also don't understand how to get my i value to count the number of shoes entered and then be entered as the size of my array. I am not going to lie this is a homework project and I am completely lost on it. Any examples of similar problems would be greatly appreciated.
Thanks.

I don't understand how to use structures and arrays together.

You've got a problem when you're passing the array to GetInfo(). You're passing the object, so when you modify the variable, you're actually modifying variables inside GetInfo's scope, and when the function returns, the variable will go out of scope. This means that the data entered in GetInfo will be lost. To fix this problem, you'll need to use pointers. Here is an example:

int test(int *myarray);

And to call it you would simply use test(array);

Hope this helps

This article has been dead for over six months. Start a new discussion instead.