Input from doc

Sorry for the repost I deleted the first one cause i thought i figured it out.

Im writing code to calculate how many videos will fit on a DVD that can store 120 minutes of video. The input for the program is stored in a text file.
example...

5 (number of videos, DVD #1)
5 55
6 23
4 20
2 00
3 00

3 (dvd #2)
6 43
2 32
1 45

I need it to print out the video number and amount of time, then add it to the total time.
I cant figure out where to start and how to assign the video lengths from the document to int/float? variables.
I know i need to while loop to keep getting the new variables but cant visualize how to do it.
I think i need to use an isostream with the input.txt file possibly?

I have some pseudo code...


while ( not end of file )
{
display the title of the output
keep track of the number of DVDs
set counter value
while ( counter <= numberofVideos )
{
read minute and second of a video
keep track of the total seconds
display video time and total time


Code ive got so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <string>
#include <iostream>     
#include <iomanip>     
using namespace std;


int main()                                               
{

	int video, totalMinutes, totalSeconds, videoMinutes, videoSeconds, totalVideos;
	cout << "Number of videos: ";
	cin >> totalVideos;

	while ( !cin.eof() )
	{
		cout << "Times for DVD # 1" << endl;

		while ( ? )
		{

		cin >> videoMinutes >> videoSeconds;
		cout << videoMinutes << " " << videoSeconds << endl;

		}
	}
}
Last edited on
Can anyone give any tips???
I cant figure out how to call the .txt file
do i need to use cin.get() to get the numbers from it?
Last edited on
I basically figured it out hopefully i really need two question answered though.

How do i call my input.txt document to my program?

as decribed the input could have either zero dvds or infinite amount. how to i make it move on to the next dvd.
ie.

5 (number of videos, DVD #1)
5 55
6 23
4 20
2 00
3 00

3 (dvd #2)
6 43
2 32
1 45
Topic archived. No new replies allowed.