• 15
• 15
• 11
• 9
• 10

# c++ help

This topic is 1354 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everyone,

I'm learning c++ and thats why i'm trying to make some little programs messing with c++.

I'm trying to make a simple sort of text-based cash register system and i'm trying to input

a feature like this: you have a main function. In that main function are the steps the computer needs to act

like a cash register, like this:

.........
if(action == "sell"){
cout << "How many do you want to sell" << endl;
cin >> sellAmount;
priceTotal = sellAmount * priceProduct;
cout << "The price is ";
cout << priceTotal;



Now i want to make a file that i can import into the program. In the file are different products with all an explanation of the price (priceProduct in the above code) quantity of the product and that kind of things, so that i only have to write the universal code above once and it can be used for all the products if.

I think i have to do something with classes, but i'm not sure. I even don't know if this is possible. If it is: could you explain how to do it to.

Thanks

BTW: I find it hard to explain, so if you don't understand it feel free to ask.

##### Share on other sites

Of course it is possible though text processing can be difficult.   The simplest way to do this is a text in stream.  These classes have very similar syntax to your console streams.

http://en.cppreference.com/w/cpp/io/basic_ifstream

Then you need to come up with a format.

Here is an example

_________

Beer 12 pack

8.99

3.99

Beef Jerky

2.49

_________

As you can see there is a repeating format here.  Every data field has it's own line ( the delimiter ).  Each product has its string name, and its price.

When you parse this you can create a vector of products ( think Products class or struct ) to hold your data.

Bonus points, give each product a uniqueID ( not a string ) that can be used for identification within your app.

Edited by EddieV223

##### Share on other sites

Okay many thanks i gonna find out if i understand it :D

##### Share on other sites

I'll explain.

Upvote for Seinfield.

EDIT: Totally unrelated comment I know, give me a break.

Edited by TheChubu

##### Share on other sites

I'll explain.
Upvote for Seinfield.

Sometimes it's best to lead the student without simply giving the answers.

And no I didn't down vote you.

Edited by EddieV223