While/Nested loops

Hey guys I'm a uni student and I'm new to programming, I've never ever used loops before and I've been asked to create a programme where the user the user types in the time they want to take on their journey and then there is a list of three journeys in a text file. My application is going to calculate the time they want to take on their journey and then compare it to the three options, if the journey can be completed in one of the journeys then the result should be written on the screen and and to an output file called results.txt. If the journey can't be completed then it should only be written to the screen. The messages to the screen should only indicate if the journey is suitable of not.

This is the journey data:


Journey One
1 -Amount of changes
200 - Distance 90 -Time
100 60

Journey Two
0
300 120

Journey Three
2
50 50
50 75
100 60


This is the format it is wanted in:


<journey name>
<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).


This is what is needed in the programme:

• Writing To Files.
• Iterative Statements (while / for).
• Nested Loops.
• Conversion between decimal and 24 hour clock representations of time.

This is what I've done so far..


#include <fstream>
#include <iostream>


//This saves me writing std; all the way through the programme/
using namespace std;


int main ()

{

// Create an ifstream input stream for reading of data from the file./
ifstream outFile;
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;

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 in minutes is " << userhours*60+usermins <<endl;

while (inFile)


I don't know where else to go from this so any help will be appreciated!

{

}

//This will keep the programme open./
cin.ignore();
cin.get();
return 0;



}

Last edited on
Topic archived. No new replies allowed.