C++ virgin. INVENTORY PROGRAM

I am brand new to C++. I havent done any programming whatsoever. I am taking a class in school for it and need a lot of advice/hints from you experts out there. I am not asking you to write the program for me, I am asking for your help/hints/advice in teaching me how to write it since my teacher cant. I am supposed to write an inventory program with the following info: There are two seperate columns (product name & product code) with 6 entries in each column.

Product Name Product Code

Product A 16-M978

Product B 82-C231

Product C 49-H293

Product D 35-J596

Product E 55-Y539

Product F 97-T810

Please do not laugh but this is all i have so far.

#include <iostream>
#include <string>
using namespace std;
int main ()
{
string product; //product srting
string code; //code numer string

ANY help would be much appreciated to further my learning process. THANK YOU

Last edited on
Its good to know where to start. I would suggest putting them into a 2D array which is like

-A1- -A2-
1 -- 2
1 -- 2
1 -- 2

Its not the hardest topic to learn so just look up arrays on this site.
Last edited on
umm...
how about
1
2
3
4
cout<<"PRODUCT NAME\tPRODUCT CODE"<<endl;
cout<<"Product A\t16-M978"<<endl;
....
cout<<"Product F\t97-T810"<<endl;

And just so you know:
-endl ends the line and starts on a new line.
-\t adds a tab in between Product and Product code

I'm not sure if this is what you want though.

Edit:Or as umz says, you could put products and product codes in 2 separate arrays of strings and use a for loop to print them one by one.
In which case the code would be:
1
2
3
4
5
6
7
string product[6]={"Product A","Product B",...,"Product F"};
string code[6]={...};
cout<<"PRODUCT NAME\tPRODUCT CODE"<<endl;
for(int i=0;i<6;++i0
{
cout<<product[i]<<'\t'<<code[i]<<endl;
}

Although thats not exactly what umz said :P
I think you should stick with the first way though, since you're new and probably haven't learnt loops yet.
Last edited on
OK i got the product string [6] and code string [6] set up like above.
now the problem i am having is getting to display whats in the two strings. how would i do that??? THANX
You use the for loop like poke386 shows. When all the data is stored in the arrays each one has a reference e.g. arr1[0] = "Product A" or whatever, you just gotta use the loop to go through the array and cout<< them all.
Use the above code from poke386 as a guideline
Topic archived. No new replies allowed.