-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcs135_A8.cpp
73 lines (62 loc) · 1.37 KB
/
cs135_A8.cpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//Captain-Price-TF-141
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void readFromFile(int list[], int& size, ifstream& infile) //reads in-file input text
{
int i = 0; //
int number = 0; //
while (infile >> number) // loop, until end of numbers
{
list[i] = number; //array counter
i++;
}
size = i;
}
bool getToLastIndex(int list[], int size) //determines if the last index can be reached
{
int i = 0; //
int j = 0; //
for (i = 0; i < size;)
{
if (list[i] == 0)
break;
j = i + list[i];
i = j;
}
if (j >= size)
return true; //if last index item is reachable
else
return false; //if last index item is not reachable
}
int main()
{
char filename[50]; //
cout << "Enter filename: "; //input file name
cin >> filename;
FILE *fp;
fp = fopen(filename, "r");
while (fp == NULL)
{
cout << endl << "Enter filename: "; // loop, input file name again if wrong
cin >> filename;
fp = fopen(filename, "r");
}
ifstream fin;
fin.open(filename);
int jump[50]; //
int s = 0;
int i = 0;
readFromFile(jump, s, fin);
if (getToLastIndex(jump, s))
{
cout << "Mario FTW" << endl; //output correct result
}
else
{
cout << "This bridge has the workings of bowser all over it >:(" << endl; //output wrong result
}
fin.close();
return 0;
}