-
array or int
Okay I want to make a program were the user inputs a name of an item and the proce of the item than keeps doing it till the user want to stop. Now my question is how should I store the users input? through multable varables...
Code:
char ItemOne
int itemPriceOne
or use arays
Code:
string itemname[128]
int itemprice[128]
int main()
{
cout << "Enter item name: "
cin << itemname[1]
if(itemname[1] = "done")
{
displayinfo(void)
}
else
{
main()
}
now that isn't my finle program it is just an idea of what i want to do. So should I use varables or arrays?
~StormTrooper
-
Well you could use some other container like linked list or vector :P...but I assume you are new to C++ so it would probably be a good idea to use an array, if only to get a better understanding of how to use them. Also if you use an array you can use a variable that is incremented in each loop to access/change the element:
Code:
for (int i=0;i<lgnthOfArray;i++)
{
...
cin>>array[i];
}
-
Code:
for (int i=0;i<lgnthOfArray;i++)
{
...
cin>>array[i];
}
okay do i need to int lgnthOfArray int it? so the code would be...
Code:
int IN; //Int Item name
int IP; // int Item Price
int main()
{
cout << "Enter in a Product Name: ";
cin >> ItemName[IN];
cout << "Enter in the products price: $ ";
cin >> ItemPrice[IP]
IN++;
IP++;
for (i <= 10) || (ItemName[I] = "Done") || (ItemName[i] = "done")
{
displayInfo(void)
}
right?