Fruit Sales assignment

Hello I have been faced with a difficult problem domain. I am getting tons of errors.Any help would be appreciated, thank you.

--------------------------------------
PROBLEM DOMAIN:

Write a program which asks the user which fruits he wants to purchase and in how much quantity. Based on the input from the user, it produces a bill. Make use of the following data:

Banana $1 per lb

Apple $2 per lb

Pears $2.5 per lb

Oranges $1.5 per lb

pappya $1.40 per


Here is an example:



Do you want to purchase fruit? Yes

Which fruit? Orange

How many pounds ? 2

Do you want to purchase another fruit? Yes

Which fruit? Apple

How many pounds? 1.5

Do you want to purchase anothe fruit? No

Thanks for your business.

Here is your bill:

Fruit Quantity Price per Lb Price

Orange 2 Lb 1.5 3

Apple 1.5 Lb 2 3

Total Amount 6


The input from the user is in bold letters.
------------------------------
Declare two structs. One to store the fruit name and price per pound. Other to store the fruit name, quantity ordered, price per pound and total price for a given fruit. Declare two arrarys of these two structs and store the required information which is either hard coded or given by the user. Then loop through to print the bill.

If you are not able to get the spacing correct in the bill, that is fine and no marks will be deducted for that. However the information must be correct.
-----------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 
//Fruit_Sales.cpp
//Name: Siddarth Anney
//Date: 2/14/2014
//COSC-1415-73426
//Prof Sharma

#include <iostream>
#include <cstring>
using namespace std;


void main()



{
	struct fruit
{
	char fruitName[10];
	float price;
};

struct customers
{
	char fruitName[10];
	float quantity_ordered;
	float price;
	float total_price;
};


	char choice;
	string fruit_choice;
	float pounds_choice;
	int count=0;

	fruit fruits[5];
	customer customers[5];

	strcpy(fruits[0].fruitName, "Banana");
	strcpy(fruits[1].fruitName, "Apple");
	strcpy(fruits[2].fruitName, "Pears");
	strcpy(fruits[3].fruitName, "Oranges");
	strcpy(fruits[4].fruitName, "Papaya");

	fruits[0].price=1;
	fruits[1].price=2;
	fruits[2].price=2.5;
	fruits[3].price=1.5;
	fruits[5].price=1.40;

	strcpy(customers[0].fruitName, "Banana");
	strcpy(customers[1].fruitName, "Apple");
	strcpy(customers[2].fruitName, "Pears");
	strcpy(customers[3].fruitName, "Oranges");
	strcpy(customers[4].fruitName, "Papaya");

	customers[0].price=1;
	customers[1].price=2;
	customers[2].price=2.5;
	customers[3].price=1.5;
	customers[4].price=1.40;


	cout << "Welcome to the fruit market" << endl;
	cout << "Would you like to purchase fruit?" << endl;
	cin >> choice >> endl;

	while (choice == 'Y')
	{
	cout << "Which fruit?" << endl;
	cin >> fruit_choice >> endl;

	cout << "How many pounds?" << endl;
	cin >> pounds_choice >> endl;
	
	if (fruit_choice == "Banana")
	{
	customers[0].quantity_ordered = pounds_choice;
	customers[0].total_price = customers[0].quantity_ordered * customers[0].price;
	}
	else if (fruit_choice == "Apple")
	{
	customers[1].quantity_ordered = pounds_choice;
	customers[1].total_price = customers[1].quantity_ordered * customers[1].price;
	}
	else if (fruit_choice == "Pears")
	{
	customers[2].quantity_ordered = pounds_choice;
	customers[2].total_price = customers[2].quantity_ordered * customers[2].price;
	}
	else if (fruit_choice == "Oranges")
	{
	customers[3].quantity_ordered = pounds_choice;
	customers[3].total_price = customers[3].quantity_ordered * customers[3].price;
	}
	else (fruit_choice == "Papaya")
	{
	customers[4].quantity_ordered = pounds_choice;
	customers[4].total_price = customers[4].quantity_ordered * customers[4].price;
	}
	}

	for (count = 1 ; count <=5 ; count++)
	{
	if (customers[0].total_price != 0)
	{
		cout << customers[0].fruit_name <<
		cout << customers[0].quantity_ordered <<
		cout << customers[0].price <<
		cout << customers[0].total_price <<

	}
	}



}


closed account (iAk3T05o)
Structs go outside int main() not void main() and you don't put the array in the struct.
Last edited on
ok here is the revised code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#include <string>
using namespace std;

struct fruitData
{
	string fruitName;
	float price;
};

struct invoiceData
{
	char fruit_ordered;
	float price1;
	float quantity_ordered;
	float totalFruitprice;
} ;



int main()

	char choice;
	string fruit_choice;
	float pounds_choice;
	int count=0;

	fruitData fruits[5];
	invoiceData customers[5];

	strcpy(fruits[0].fruitName, "Banana");
	strcpy(fruits[1].fruitName, "Apple");
	strcpy(fruits[2].fruitName, "Pears");
	strcpy(fruits[3].fruitName, "Oranges");
	strcpy(fruits[4].fruitName, "Papaya");

	fruits[0].price=1;
	fruits[1].price=2;
	fruits[2].price=2.5;
	fruits[3].price=1.5;
	fruits[5].price=1.40;

	strcpy(customers[0].fruitName, "Banana");
	strcpy(customers[1].fruitName, "Apple");
	strcpy(customers[2].fruitName, "Pears");
	strcpy(customers[3].fruitName, "Oranges");
	strcpy(customers[4].fruitName, "Papaya");

	customers[0].price=1;
	customers[1].price=2;
	customers[2].price=2.5;
	customers[3].price=1.5;
	customers[4].price=1.40;


	cout << "Welcome to the fruit market" << endl;
	cout << "Would you like to purchase fruit?" << endl;
	cin >> choice >> endl;

	while (choice == 'Y')
	{
	cout << "Which fruit?" << endl;
	cin >> fruit_choice >> endl;

	cout << "How many pounds?" << endl;
	cin >> pounds_choice >> endl;
	
	if (fruit_choice == "Banana")
	{
	customers[0].quantity_ordered = pounds_choice;
	customers[0].total_price = customers[0].quantity_ordered * customers[0].price;
	}
	else if (fruit_choice == "Apple")
	{
	customers[1].quantity_ordered = pounds_choice;
	customers[1].total_price = customers[1].quantity_ordered * customers[1].price;
	}
	else if (fruit_choice == "Pears")
	{
	customers[2].quantity_ordered = pounds_choice;
	customers[2].total_price = customers[2].quantity_ordered * customers[2].price;
	}
	else if (fruit_choice == "Oranges")
	{
	customers[3].quantity_ordered = pounds_choice;
	customers[3].total_price = customers[3].quantity_ordered * customers[3].price;
	}
	else (fruit_choice == "Papaya")
	{
	customers[4].quantity_ordered = pounds_choice;
	customers[4].total_price = customers[4].quantity_ordered * customers[4].price;
	}
	}

	for (count = 1 ; count <=5 ; count++)
	{
	if (customers[0].total_price != 0)
	{
		cout << customers[0].fruit_name <<
		cout << customers[0].quantity_ordered <<
		cout << customers[0].price <<
		cout << customers[0].total_price <<

	}
	}



}


when i hover over stycpy it says "this declaration has no storage class or type specifier"
closed account (iAk3T05o)
Why do you have to use strcpy and why do you do the same things twice? I don't know strcpy does but customers[0].fruitname = "banana"; should do what you need it to and involves less code (functions may produce the least code).
Topic archived. No new replies allowed.