I have assignment to do, but i dont know how to start it off. I read from a text file( also print movies r playing first) , read each line and assign to each string and next line is the price so and customer should be able to choose a more then one movie, and at the end print the add up the price with tax(5%). can some one help me please. Thankx alot in advance.
so here is the output should be like
This is my movie.txt file -
Transformers
-
$8.50
-
Rush Hour 3
-
$8.50
-
The Game Plan
-
$9.50
-
-
This is Output I want. -
Movies that are Playing now:
-
-
Transformers $8.50
-
Rush Hour 3 $8.50
-
The Game Plan $9.50
-
-
Your Movie Ticket:
-
-
Rush Hour 3 $8.50
-
The Game Plan $9.50
-
-
Total: $18.00
-
Tax: $0.90
-
Amount Due: $18.90
-
-
15 5175
I have assignment to do, but i dont know how to start it off. I read from a text file( also print movies r playing first) , read each line and assign to each string and next line is the price so and customer should be able to choose a more then one movie, and at the end print the add up the price with tax(5%). can some one help me please. Thankx alot in advance.
so here is the output should be like
This is my movie.txt file -
Transformers
-
$8.50
-
Rush Hour 3
-
$8.50
-
The Game Plan
-
$9.50
-
-
This is Output I want. -
Movies that are Playing now:
-
-
Transformers $8.50
-
Rush Hour 3 $8.50
-
The Game Plan $9.50
-
-
Your Movie Ticket:
-
-
Rush Hour 3 $8.50
-
The Game Plan $9.50
-
-
Total: $18.00
-
Tax: $0.90
-
Amount Due: $18.90
-
-
Which part of this you cannot figure out?
Savage
PS:Please read our posting guidelines
Which part of this you cannot figure out?
Savage
PS:Please read our posting guidelines
Like how to start off da program. i could get struct fuction in put file, i could get to da point where it will print whole file in screen but i dont kno whow to get each line and assingt it to each string. like let say -
struct movieNametype
-
{
-
char movieName [ ]
-
double price;
-
}
-
-
movieItemtype movies[30];
so let say - ifstream InFile;
-
InFile.open ("movies.txt");
so here is the question how do i get to read each line from "movies.txt" file and assign it like this - movies[0].movieName="Rush Hour 3";
-
movies[0].price=8.50;
and this repeats until to end of it.
Like how to start off da program. i could get struct fuction in put file, i could get to da point where it will print whole file in screen but i dont kno whow to get each line and assingt it to each string. like let say
struct movieNametype
{
char movieName [ ]
double price;
}
movieItemtype movies[30];
so let say
ifstream InFile;
InFile.open ("movies.txt");
so here is the question how do i get to read each line from "movies.txt" file and assign it like this
movies[0].movieName="Rush Hour 3";
movies[0].price=8.50;
and this repeats until to end of it.
See this
Savage
Yea i read that before, but i dont get it how to read from file and assign to string line by line.
Yea i read that before, but i dont get it how to read from file and assign to string line by line.
You're going to need an array of strings, and if you can't read that and figure out how to read from a file, you're going to have to tell us why you don't understand that - we can't read your mind and figure out what you're stuck on.
okay, let say
cout<<"movie name: ";
cin>>movie_name;
okay so how do i get each line from a file (movies.txt) and
cin>>movies[0].movieName;
so if first line in file says Rush hour 3
it should be stored in movies[0].movieName
.. i guess i explained ma self this time?
okay, let say
cout<<"movie name: ";
cin>>movie_name;
okay so how do i get each line from a file (movies.txt) and
cin>>movies[0].movieName
Yep. That's pretty much exactly it, only in a loop so that you pull the line in to a different spot in the array each time, and you test that the file hasn't reached the end. You'll probably want to increment the array index, and you're not using cin. I believe there's another that might be better for C++, let me look it up.
But aside of that (and having looked at the getline page) do you understand it? If not, can you post the line you're having trouble with?
#include <fstream>
fstream InFile;
char str[2000];
InFile.open ("C:\Documents and Settings\%username%\Desktop\movie_c\movie.txt",ios ::in);
while (!InFile.eof())
{
InFile.getline(str,2000);
cout<<str;
}
it compiles but, i dont get any output in screen?
it compiles but, i dont get any output in screen?
Have you added:
at the end??
Savage
Have you added:
at the end??
Savage
yea,, i have getch(). wat i ment i dont get anything on screen for output is dat... i dont get any output. screen is there but No OUTPUT whatsoever.
You need to post the code - we're sitting here guessing and giving you functions, but we've seen no implementation. If you're not getting output, are you getting errors? Are you printing stuff out, or are you printing stuff to a file? I know you're reading in from a file (wasn't that in your original problem?), so are you printing it out after that, or are you just performing some action (adding movie to db, removing from collection, throwing it against the wall, etc...) and then not printing to standard output (cout) the success or failure of that?
You need to post the code - we're sitting here guessing and giving you functions, but we've seen no implementation. If you're not getting output, are you getting errors? Are you printing stuff out, or are you printing stuff to a file? I know you're reading in from a file (wasn't that in your original problem?), so are you printing it out after that, or are you just performing some action (adding movie to db, removing from collection, throwing it against the wall, etc...) and then not printing to standard output (cout) the success or failure of that?
Code that i have in my previous post. datz one i am useing to read from jst file and print out thats it. same code. it compiles everything no error, but in OUTPUT SCREEN, nutthing prints on it. so i dont know what is the problem there because, there is no error or anything it just doesnt print anything on it.
Can you post your whole program?
Can you post your whole program?
-
{
-
-
char str[2000];
-
fstream file_op("C:\Documents and Settings\Administrator\Desktop\menu_c\menu.txt",ios::in);
-
while(!file_op.eof())
-
{
-
file_op.getline(str,2000);
-
cout <<str;
-
} file_op.close();
-
cout <<endl;
-
-
-
}
First of all, you need to put 'using namespace std;' after your library declarations. -
fstream file_op("C:\Documents and Settings\Administrator\Desktop\menu_c\menu.txt",ios::in);
-
Then, I believe this is your problem, you need to be backwhacking the filepath - the compiler interprets a single backslash as an escape character so you can use things like \n, \t, etc... which are newline and tab characters. So your compiler is trying to figure out what \D, \A, \m mean, etc... So you need C:\\Documents and Settings\\yourpath\\your file.
PS - as we have a policy against posting full code, I've snipped it down, but that's just due to the forum rules.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: JasBascom |
last post by:
I have written a program that is suppose to compare to lines
c12345
I04567
the program takes the first digit encountered of both lines, decides which one
is smaller and writes that to a file...
|
by: Mahmood Ahmad |
last post by:
Hello,
I have written a program that reads three types of records, validates
them acording to certain requirements and writes the valid records
into a binary file. The invalid records are...
|
by: JasBascom |
last post by:
I thought it was too much to put this program in with my last message. The
program compiles ok, but when I execute, I get access errors.
can someone put it through their compiler please. I think...
|
by: Baloff |
last post by:
Hello
I wrote a code which is suppose to read a file which contains lines of
double and prints it out.
thanks for helping
double.txt***************************************
1.01
2.0301
|
by: soulhack |
last post by:
Hey!
Im working on a movie list, but i donīt get the delete part of it to work.
Help please :p
Many thanks//SoulHack
# include <iostream.h>
# include <conio.h>
# include <string.h>
#...
|
by: gdarian216 |
last post by:
I have written a c++ program that takes input from a file and outputs the average. The program uses structs and I need to convert the struct to a class.
I just dont know how to get started and if...
|
by: gdarian216 |
last post by:
the program reads input from a file and then outputs the averages and grade.
for some reason it is reading in the same line twice and it doesn't print out the grade. everything else is correct, if...
|
by: charmeda103 |
last post by:
i have this program that i am almost done with, i am one part away from being done.
the last part is putting the results together;
here is the results that i need to put in code. do u have any...
|
by: charmeda103 |
last post by:
when i run my program it runs with no erorrs but the output screen is giving me strange results
here is whats its giving me:
CONFERENCE OVERALL
RANK TEAM W-L % WINS MARGIN W-L ...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| | |