How to do this in c++, FILING QUESTION?

I have this data in a file
Apples 80
Rice 100
Jam 95
Ketchup 200

Now what I want is that when user enters rice, then the program checks in this file, the price of rice and displays it on the screen.

Please this is very urgent, I need this code for my viva on monday

This is programming. What you thought was programming was in fact just memorising syntax. If you struggle to think about how to do this, programming isn't for you.

-------------

Open file

Get word from user

Read two words from file. If first word matches user input, output second word and end. If first word does not match, read in next two words and repeat.

Last edited on
Please I really need this code, I know programming is not for me, I am BS EE student, but I have to pass this C++ course no matter what
Have you read your textbook?

Here's section in the tutorial on files that may help you out:
http://cplusplus.com/doc/tutorial/files/
Yes I have but still unable to do it, please just write me the code, i need it urgently
Just post what you have done so far and we'll help you through it...

Nobody cares how "urgent" it is, everybody says that when they haven't done their homework. Don't fool yourself either, you will get NOWHERE in EE these days without good programming skills. Except for a few niche products you'll find that almost all "analog circuitry" out there is DSP running in an FPGA. The ability to write good code is no longer optional.

Try it. You have plenty of time to work this simple problem out by Monday... You might even like it!
Okay I wrote the code myself, thanks a lot for the motivation. Had to search for different functions for like hours but learned a lot
Topic archived. No new replies allowed.