What's wrong with my code?
Inventory isn't displaying
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
|
#include <iostream>
#include <string>
using namespace std;
void display(int, string*);
int main()
{
int size;
cout << "Enter the size of your inventory.\n";
cin >> size;
string* inventory = new string[size];
for (int i = 0; i < size; ++i)
{
cout << "Enter the name of your items: ";
cin >> inventory[i];
}
display(size, inventory);
delete[] inventory;
inventory = nullptr;
int k;
cin >> k;
return 0;
}
void display(int inventorysize, string* inventory)
{
for (int i = 0; i < inventorysize; ++i)
{
cout << inventory[inventorysize];
}
}
|
Please help
cout << inventory[inventorysize];
should be cout << inventory[i];
LOL silly me always make stupid mistakes, if my professor was here he would've slapped me on my wrist :p thank you gib.
I would suggest getting a new professor lol. Everyone makes simple mistakes like that :P. Sometimes it just takes a second pair of eyes to notice.
Topic archived. No new replies allowed.