unititialized variable? I'm stumped

This is a homework assignment and I have it done....
except it tells me "k is not initialized"
I'm using Visual Studio 2010

Good Karma to anyone that can help me out!

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
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

//structure definition
struct menuitemType
	{
		string menuitem [10];
		float menuprice [10];
	};

//prorotype declaration
void getdata (menuitemType &m, int &c, int q[]);
void showmenu ();
void printcheck (menuitemType &m, int c, int q[]);

void main()
{
	menuitemType menulist;
	int c, quantity[10];
	showmenu ();
	getdata (menulist, c, quantity);
	printcheck (menulist, c, quantity);
	system ("pause");
}

//fund=ction definitions
	void showmenu ()
	{
		cout<<"Welcome to Johnny's Restaurant"<<endl<<endl;
		cout<<"MENU"<<endl<<endl;
		cout<<"1) Plain Egg"<<"\t\t"<<"$1.45"<<endl<<endl;
		cout<<"2) Bacon and Egg"<<"\t\t"<<"$2.45"<<endl<<endl;
		cout<<"3) Muffin"<<"\t\t\t"<<"$0.99"<<endl<<endl;
		cout<<"4) French Toast"<<"\t\t"<<"$1.99"<<endl<<endl;
		cout<<"5) Fruit Basket"<<"\t\t"<<"$2.49"<<endl<<endl;
		cout<<"6) Cereal"<<"\t\t\t"<<"$0.69"<<endl<<endl;
		cout<<"7) Coffee"<<"\t\t\t"<<"$0.50"<<endl<<endl;
		cout<<"8) Tea"<<"\t\t\t"<<"$0.75"<<endl<<endl;
	}

	void getdata (menuitemType &m, int &c, int quantity[])
	{
		int k;
		int choice;
		cout<<"Enter the number of items. "<<endl;
		cin>>c;
		for (k+0; k<c; k++)
		{
			cout<<"Enter the menu item selected. "<<endl;
			cin>>choice;
			cout<<"Enter the quantity of the item. ";
			cin>>quantity[k];
			switch (choice)
			{
			case 1:m.menuitem[k]="Plain Egg";
				m.menuprice[k]=1.45;
				break;
			case 2:m.menuitem[k]="Bacon and Egg";
				m.menuprice[k]=2.45;
				break;
			case 3:m.menuitem[k]="Muffin";
				m.menuprice[k]=0.99;
				break;
			case 4:m.menuitem[k]="French Toast";
				m.menuprice[k]=1.99;
				break;
			case 5:m.menuitem[k]="Fruit Basket";
				m.menuprice[k]=2.49;
				break;
			case 6:m.menuitem[k]="Cereal";
				m.menuprice[k]=0.69;
				break;
			case 7:m.menuitem[k]="Coffee";
				m.menuprice[k]=0.50;
				break;
			case 8:m.menuitem[k]="Tea";
				m.menuprice[k]=0.75;
				break;
			}
		}
	}

	void printcheck (menuitemType &m, int c, int quantity [])
	{
		int j;
		float price = 0.0, tax = 0.0, total;
		cout<<"Welcome to Johnny's Restaurant"<<endl;
		for (j=0;j<c;j++)
		{
			cout<<quantity[j]<<" "<<m.menuitem[j]<<" "<<m.menuprice[j]*quantity[j]<<endl;
			price=price + (m.menuprice[j]*quantity[j]);
		}
		tax= 0.06*price;
		total=tax+price;
		cout<<setprecision(2);
		cout<<"Tax = "<<tax<<endl;
		cout<<"Amount due = "<<total<<endl;
	}
line 50: for (k+0; k<c; k++)
How should it be rewritten? I know where it says the error is, but I don't understand why.
*facepalm for(k=0; k<c; k++)
How can you add to k if it doesn't have a value yet?
http://cplusplus.com/doc/tutorial/control (See: "The For Loop")
Last edited on
Facepalm indeed!

THANKS!!!!!!!!!!!!!!!!!!!!
Topic archived. No new replies allowed.