I am getting the following two errors, i am lost on how to fix them:

Exc_3.cpp(54) : error C2082: redefinition of formal parameter 'name'
Exc_3.cpp(54) : error C2440: 'initializing' : cannot convert from 'char[]' to 'char'

Here was my original prompt, I think i did part B wrong.....wasn't sure how to pass the address of it.

a. Write a function that passes a box structure by value and that displays the value of
each member.
b. Write a function that passes the address of a box structure and that sets the volume
member to the product of the other three dimensions.
c. Write a simple program that uses these two functions.

//Exc_3.cpp - Box structure with functions

#include<iostream>
#include<string>

using namespace std;

struct box
{
	char maker[40];
	float height;
	float width;
	float length;
	float volume;
};

void displayBox(string name);
void createNewBox(char maker[], float height, float width, float length);
void passAddressBox(string name);

int main()
{
	cout << "Let's make a box!" << endl;
	float width, height, length;
	char maker[40];
	cout << "Name of box: ";
	cin >> maker;
	string name = maker;
	cout << "Height of box: ";
	cin >> height;
	cout << "Length of box: ";
	cin >> length;
	cout << "Width of box: ";
	cin >> width;
	createNewBox(maker, height, width, length);
	displayBox(name);
	cout << "Now box will be different!" << endl;
	passAddressBox(name);
	displayBox(name);
	system("PAUSE");
}

void displayBox(box variable)
{
	cout << "Maker: " << variable.maker << endl;
	cout << "Height: " << variable.height << endl;
	cout << "Width: " << variable.width << endl;
	cout << "Length: " << variable.length << endl;
	cout << "Volume: " << variable.volume << endl;
}	

void createNewBox(string name, char maker[], float height, float width, float length)
{
	box name = {maker, height, width, length, 0.0};
}

void passAddressBox(box temp)
{
	float temporary = temp.length * temp.height * temp.width;
	temp.volume = temporary;
}

Thanks for the help.

in your createNewBox() function you have a parameter name then you try to redefine it with a box datatype

instead, your function should be datatype box and return the new box, or add a box &b parameter and set that variable as the output box

Still having issues, now it is complaining about my line 56 with the {, }, ;'s....

//Exc_3.cpp - Box structure with functions

#include<iostream>
#include<string>

using namespace std;

struct box
{
	char maker[40];
	float height;
	float width;
	float length;
	float volume;
};

void displayBox(string name);
void createNewBox(char maker[], float height, float width, float length, box &data);
void passAddressBox(string name);

int main()
{
	cout << "Let's make a box!" << endl;
	box *data = new box;
	float width, height, length;
	char maker[40];
	cout << "Name of box: ";
	cin >> maker;
	string name = maker;
	cout << "Height of box: ";
	cin >> height;
	cout << "Length of box: ";
	cin >> length;
	cout << "Width of box: ";
	cin >> width;
	createNewBox(maker, height, width, length, *data);
	displayBox(name);
	cout << "Now box will be different!" << endl;
	passAddressBox(name);
	displayBox(name);
	delete data;
	system("PAUSE");
}

void displayBox(box variable)
{
	cout << "Maker: " << variable.maker << endl;
	cout << "Height: " << variable.height << endl;
	cout << "Width: " << variable.width << endl;
	cout << "Length: " << variable.length << endl;
	cout << "Volume: " << variable.volume << endl;
}	

void createNewBox(string name, char maker[], float height, float width, float length, box &data)
{
	data = {maker, height, width, length, 0.0};
}

void passAddressBox(box temp)
{
	float temporary = temp.length * temp.height * temp.width;
	temp.volume = temporary;
}

You do realize you can only instantiate like

int arr[]={9,0,...,6};

only upon declaration.

Anything other than that, use a parameterized ctor.
Instead you should alloc memiry to data inside the createNewBox()

data = new box(maker, height, width, length, 0.0);

Edited 6 Years Ago by nbaztec: n/a

Almost there.....

C2661: 'box::box' : no overload function that takes 5 arguments

//Exc_3.cpp - Box structure with functions

#include<iostream>
#include<string>

using namespace std;

struct box
{
	char maker[40];
	float height;
	float width;
	float length;
	float volume;
};

void displayBox(string name);
void createNewBox(char maker[], float height, float width, float length, box &data);
void passAddressBox(string name);

int main()
{
	cout << "Let's make a box!" << endl;
	box *data = new box;
	float width, height, length;
	char maker[40];
	cout << "Name of box: ";
	cin >> maker;
	string name = maker;
	cout << "Height of box: ";
	cin >> height;
	cout << "Length of box: ";
	cin >> length;
	cout << "Width of box: ";
	cin >> width;
	createNewBox(maker, height, width, length, *data);
	displayBox(name);
	cout << "Now box will be different!" << endl;
	passAddressBox(name);
	displayBox(name);
	delete data;
	system("PAUSE");
}

void displayBox(box variable)
{
	cout << "Maker: " << variable.maker << endl;
	cout << "Height: " << variable.height << endl;
	cout << "Width: " << variable.width << endl;
	cout << "Length: " << variable.length << endl;
	cout << "Volume: " << variable.volume << endl;
}	

void createNewBox(string name, char maker[], float height, float width, float length, box &data)
{
	data = new box (maker, height, width, length, 0.0);
}

void passAddressBox(box temp)
{
	float temporary = temp.length * temp.height * temp.width;
	temp.volume = temporary;
}
This article has been dead for over six months. Start a new discussion instead.