Hey guys, I'm a uni student new to programming so I only know the basics. Basically I have to create a nested loop in my program so once the user has entered the time they want to travel it will come up on the screen the best journey to travel.
Here's the bit I cant do..
The task requires you to produce an application that first requests a time period from the user then proceeds to read the available journeys from a file, in the following format:
<c> // where c is the number of changes
<dn><sn> // for each leg n, dn is the distance and sn is the speed. Note n=(c+1).
Your application will calculate the total journey time for each journey and then compare it with the time period specified by the user. If the journey can be completed in the specified time then the result must be written to the screen and to an output text file called results.txt. If the journey cannot be completed in time then the results must be written to the screen only. Messages to the screen must indicate whether the journey is suitable or not.
The file I have to read from is set out a bit like
1 - That being the amount of times you have to swap trains
200 - Miles 90 - Time
100 - Miles 60 - Time
Help will be much appreciated as I am so confused and have no idea where to go with this because all I have done so far is where the user enters their time and it will convert it to minutes.
//This saves me writing std; all the way through the programme/
int main ()
// Create an ifstream input stream for reading of data from the file./
outFile.open("Task 3 data.txt", ifstream::in +ifstream::binary);
//These are the different variables I will use, I have appreviated these so it will be quicker for me to type them eg. j1l stands for journey1length./
int time, j1l, j2l, j3l, usermins, userhours, usertime;
cout <<"Journey Planner" <<endl;
//This will show this message on the screen and the user will enter how long they want to spend on their journey./
cout <<"Please enter the max time you would like to spend on your journey " <<endl;
cout <<"Hours" <<endl;
cin >> userhours;
cout <<"Minutes" <<endl;
cin >> usermins;
//This is going to show the user how many minutes they will be travelling for./
cout <<"The total time you will be traveling is ";
cout << usertime;
cout << " minutes";
//This will keep the programme open./
I have to include a nested loop in the program that will take the usertime and then look in this file
and then will tell you by the time you have entered what journey is the best to take. The ones that aren't good enough will only be shown to the screen but the journeys that can be taken will be shown to the screen and to a file.
I have in the past created a program where it reads from another file, but that was very simple and I just entered my own numbers in to it and it would read it line by line, but this time it is meant to read from this file