Ok, so I am a novice C++ programmer and I wanted to make a program that indexs products. The program would hold the price of a product and the name and the user would be able to input the data and could then view the items by a sort of search system by searching an array where the name and price was.
How could I create this search system searching the array AND how could I get the data to be placed in the array so that the next time it place the data in the next slot?
Sorry if this sounds noobish question and I am sure the latter question, I know how to do.
Well don't worry man, this isn't really a noobish question; as it is posted in the beginners forums. You're supposed to ask questions. Anyways, what do you have so far? I'm sure you'd need some char, if, and else if stuff;
#include <iostream>
usingnamespace std;
int oneOrTwo = 0;
int one,One,two,Two;
char productName[126];
char productPrice[126];
char yesOrNo[50];
int main() {
while (oneOrTwo != 1 || one || One || 2 || two || Two) {
cout << "Hello and welcome to Arcadiu's product indexer. To add a item, enter 1. To search for a item, press 2.\n";
cin >> oneOrTwo;
if (oneOrTwo == 1)
while (yesOrNo == 2) {
cout << "Ok. To start, please enter the name of the product you wish to index.\n";
cin >> productName[0];
cout << "Next, enter the price for the item (for one of the item).\n";
cin >> productPrice[0];
cout << "So the product name was" << productName[0] << ", and the price for that was" << productPrice[0] <<"?"
cout << " If that is correct, type yes to continue, if not, type no to redo the product indexing.";
cin >> yesOrNo[50];
}
if (yesOrNo == yes || Yes)
cout << "Would you like to enter another product? Type yes to create another item or no to return to the menu.";
cin >> yesOrNo[50];
if (oneOrTwo == 2 || two || Two)
cout << "\n";
}
return 0;
}
Yes, yes I know its awful, no functions, rubbish standards and I am using a number system for choices because I dont no how to do anything else. It is littered with errors and I still dont have that array problem solved and to get it right it will have to decerement and increment into which array the info is placed in if you are to write over things.
I was probably going too ambitious but I would still like to know those things and how it could of been done.
you could create an array of strings and have the name of the product and price next to eachother in the array. then have the products printed and allow the user to enter a product name, then just search through the array looking for that product and print the next element in the array - which would be the price.
well mcleano I created 2 arrays, one for price and one for product and the product and price would be in the same slots for each array for example if I created a product, the name would go in productName[0] and the price in productPrice[0] so when you called for productPrice and productName, they would both come out as they were entered.
I didnt think you could actualy "search" an array but yes i know i wanted to know how to do it but I didnt no it was possible. All the array info I have read about has never gone that deep. Not even the www.cplusplus.com reference or w/e section has that sort of information.
YES! Thats exactly what I was getting at. I knew that array placing data thingy was right under my nose :) Thank you very much. Could I ask what cin.get() is? Am I right in saying that that gets the WHOLE string because if you just used cin for it, it would only get 1 word because a string terminates after a white space or a null? Would I have to say the strings string array and int numarray and then the buffer size?