C++ application crash after computing area - c++

I'm just curious why my application actually crashes after it compute the area of a cross.
I output is correct but it crashes after it calculation is done.
cross.cpp
void Cross::setCrossCord()
{
for (int i=1; i<=12; i++)
{
cout << "Please enter x-ordinate of pt " << i << ": ";
cin >> xVal;
xvalue[i] = xVal;
cout << endl;
cout << "Please enter y-ordinate of pt " << i << ": ";
cin >> yVal;
yvalue[i] = yVal;
cout << endl;
}
}
double Cross::computeArea()
{
int points = 12;
int running_total = 0;
for (int i=0; i<=12-1; i++)
{
running_total = (xvalue[i]*yvalue[i+1]) - (xvalue[i+1]*yvalue[i]); //cross calculation of coord in a cross
} //(x1*y2)-(y1*x1)
running_total = (xvalue[points-1]*yvalue[0]) - (xvalue[0]*yvalue[points-1]); // traverse back to the origin point
// (xn*y1)-(yn*x1)
area = abs(running_total / 2); //purpose of absolute is to make sure result is positive.
//polygon are specified in counter-clockwise order (i.e. by the right-hand rule), then the area will be positive.
cout << "area of cross is: " << area << endl;
return (area);
}
int main()
{
Cross cross;
string shapetype;
cout << "enter shape type: " << endl;
cin >> shapetype;
if(shapetype == "cross")
{
cross.setCrossCord();
}else
{cout << "error" << endl;};
cross.computeArea();
}
this is the error I'm getting from windows, and I'm puzzled why this is happening.

You must change the for loop in setCrossCord to be zero - based:
// change
for (int i=1; i<=12; i++)
// to
for (int i=0; i<12; i++)
Because arrays (and vectors etc.) are zerobased in C++
In fact you can see that this it the intended range because of the loop in computeArea.
The reason that the program crashes only after the computation is because out-of-bounds processing (specifically, writing) invoked Undefined Behaviour: it may crash or do random stuff: it's not error detection.
Here's a 'technically' fixed version of your code: Live on Coliru
However, you'd do good to (re)design your class to have only 1 responsibility (namely: represent a Cross, not do input or output. Also, the temporaries xVal and yVal should not live beyond the input procedure (and could be merged)).
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
struct Cross
{
double xvalue[12], yvalue[12];
void setCrossCord()
{
for (int i=0; i<12; i++)
{
cout << "Please enter x-ordinate of pt " << i << ": ";
double xVal, yVal;
cin >> xVal;
xvalue[i] = xVal;
cout << endl;
cout << "Please enter y-ordinate of pt " << i << ": ";
cin >> yVal;
yvalue[i] = yVal;
cout << endl;
}
}
double computeArea()
{
int points = 12;
int running_total = 0;
for (int i=0; i<12-1; i++)
{
running_total = (xvalue[i]*yvalue[i+1]) - (xvalue[i+1]*yvalue[i]); //cross calculation of coord in a cross
} //(x1*y2)-(y1*x1)
running_total = (xvalue[points-1]*yvalue[0]) - (xvalue[0]*yvalue[points-1]); // traverse back to the origin point
// (xn*y1)-(yn*x1)
double area = abs(running_total / 2); //purpose of absolute is to make sure result is positive.
//polygon are specified in counter-clockwise order (i.e. by the right-hand rule), then the area will be positive.
return (area);
}
};
int main()
{
Cross cross;
string shapetype;
cout << "enter shape type: " << endl;
cin >> shapetype;
if(shapetype == "cross")
{
cross.setCrossCord();
}else
{
cout << "error" << endl;
};
cout << "area of cross is: " << cross.computeArea() << endl;
}

I bet your indexing is wrong - C/C++ uses 0 based indexing, hence:
for (int i=1; i<=12; i++)
and
for (int i=0; i<=12-1; i++)
are fishy.
In addition index + 1 is.

1)your code
cin>>yval;
yvalue[i]=yval;
can be changed to
cin>>yvalue[i];
2)arrays start from subscript 0 not 1
3)return something in main function(add return 0; statement in the end of main())
4)why are you returning any value from computearea() keep it void and don't return anything because you used the value in the function itself.
(i think point 3) causes the error but do correct all the four points in your code.

Related

How to solve a while loop that suddenly terminates itself?

I have code to look for permutations which takes input from the user until the user is satisfied with the amount of input added.
However, when receiving more than 4x input, the code suddenly stuck/terminated itself. I've tried changing the array type to dynamic memory, but the result continues to be the same.
Strangely when I test this code using http://cpp.sh/, it runs normally. I think the problem is with my compiler (I used VS code and MinGW to compile and run it.) What do you think is wrong?
My code is below:
#include <iostream>
#include <string>
using namespace std;
int main() {
int KombAngka;
bool Lanjut = true;
int x = 0;
int *Angka = new int(x);
string YaTidak;
while(Lanjut) {
cout << "Number-" << x + 1 << ": ";
cin >> Angka[x];
LoopYaTidak:
cout << "Are the numbers enough?(y/n)?: ";
cin >> YaTidak;
if (YaTidak == "y") {
Lanjut = false;
}
else if (YaTidak == "n") {
Lanjut = true;
}
else {
cout << "Enter the correct answer!(y/n)" << endl;
goto LoopYaTidak;
}
x++;
}
cout << "All numbers: (";
for (int z = 0; z <= x - 2; z++) {
cout << Angka[z] << ", ";
}
cout << Angka[x - 1] << ")" << endl;
cout << "The number of combinations of numbers used: ";
cin >> KombAngka;
int JumlahAngka = x;
const int StopLoop = JumlahAngka - KombAngka;
for (int i = JumlahAngka - 1; i > StopLoop; i--) {
JumlahAngka = JumlahAngka * i;
}
cout << "The number of queue numbers consisting of " << KombAngka << " different numbers are " << JumlahAngka << endl;
system("pause");
return 0;
}
This line
int *Angka = new int(x);
creates an integer on the heap with a value held by x which here it is 0.
You are accessing memory which you should not, and as mentioned by #fredrik it may cause a buffer overflow.
If you want to create an array on the heap you should do
int *Angka = new int[x];
This creates an array (on heap) of size x.
But since you are using c++ it's better to use vectors, you can simply create a vector with
std::vector<int> Angka;
Vector will take care of memory allocation and all other stuff that you would have to handle if you were to create an array with new.

Integers not getting added up correctly but doubles are working fine

I know this isnt the right kind of question to be asking, but for the life of me I could not figure out what is causing this problem.
I need to write a problem that takes a set number of integers or doubles and returns their sum.
I have written the code to make this work, making sure to check each time I changed something.
#include<iostream>
using namespace std;
template <class T>
class totalClass
{
private:
T *p;
T Total;
T sum;
int size;
public:
T total(int x)
{
size = x;
p = new T[x];
for (int i = 0; i < size; i++)
p[i] = T();
if (size > 1)
{
for (int i = 0; i < size; ++i)
{
cin >> sum;
Total += sum;
}
}
return Total;
}
};
int main()
{
int size, result1;
double result2;
cout << "Enter: ";
cin >> size;
cout << "the number of ints you wish to enter: Enter: " << size << " integers:";
totalClass<int> test;
result1 = test.total(size);
cout << " Total = " << result1 << endl;
cout << "Enter: ";
cin >> size;
cout << "the number of doubles you wish to enter: Enter: " << size << " doubles:";
totalClass<double> test2;
result2 = test2.total(size);
cout << " Total = " << result2 << endl;
}
My doubles are getting added up correctly but my integer addition always seems to add up to some crazy number. Is there something wrong with my problem that I cannot see?
If you forget to initialize a variable and attempt to use it or do math with it, you might end up with "crazy numbers." Make sure all of your variables are Initialized.

whatever i use as inputs, outputs are all zeros

This is a question i am working on:
Prompt the user to enter five numbers, being five people's weights. Store the numbers in a vector of doubles. Output the vector's numbers on one line, each number followed by one space.
Also output the total weight, by summing the vector's elements.
Also output the average of the vector's elements.
Also output the max vector element.
So far this is the code i have
#include <iostream>
#include <vector>
using namespace std;
int main() {
const int NEW_WEIGHT = 5;
vector<float> inputWeights(NEW_WEIGHT);
int i = 0;
float sumWeight = 0.0;
float AverageWeight = 1.0;
int maxWeight = 0;
int temp = 0;
for (i = 0; i < NEW_WEIGHT; i++){
cout << "Enter weight "<< i+1<< ": ";
cout << inputWeights[i]<< endl;
cin>> temp;
inputWeights.push_back (temp);
}
cout << "\nYou entered: ";
for (i =0; i < NEW_WEIGHT- 1; i++) {
cout << inputWeights.at(i)<< " ";
}
cout<< inputWeights.at(inputWeights.size() - 1) << endl;
for (i =0; i < NEW_WEIGHT; i++){
sumWeight += inputWeights.at(i);
}
cout <<"Total weight: "<< sumWeight<< endl;
AverageWeight = sumWeight / inputWeights.size();
cout <<"Average weight: "<< AverageWeight<< endl;
maxWeight= inputWeights.at(0);
for (i =0; i < NEW_WEIGHT- 1; i++){
if (inputWeights.at(i) > maxWeight){
maxWeight = inputWeights.at(i);
}
}
cout<< "Max weight: "<< maxWeight << endl;
return 0;
}
When i run this code, whatever inputs i use(for the cin>>(...)), i get all zero's as output and i do not know why. can i get some help please.
update
cleaned up the code a little by getting rid of the cout<< inputWeights[i]<< endl;
and by adjusting vector inputWeights; at the beginning of the program.But the outputs are still not exactly what they are supposed to be. Instead, only the first 2 inputted values make it as outputs. Any reason why? thanks
update this is the right or correct code. Hope it helps someone in future.
#include <iostream>
#include <vector>
using namespace std;
int main() {
const int NEW_WEIGHT = 5;
vector <float> inputWeights;
int i = 0;
float sumWeight = 0.0;
float AverageWeight = 1.0;
float maxWeight = 0.0;
float temp = 0.0;
for (i = 0; i < NEW_WEIGHT; i++){
cout << "Enter weight "<< i+1<< ": "<< endl;
cin>> temp;
inputWeights.push_back (temp);
}
cout << "\nYou entered: ";
for (i =0; i < NEW_WEIGHT- 1; i++){
cout << inputWeights.at(i)<< " ";
}
cout<< inputWeights.at(inputWeights.size() - 1) << endl;
for (i =0; i < NEW_WEIGHT; i++){
sumWeight += inputWeights.at(i);
}
cout <<"Total weight: "<< sumWeight<< endl;
AverageWeight = sumWeight / inputWeights.size();
cout <<"Average weight: "<< AverageWeight<< endl;
maxWeight= inputWeights.at(0);
for (i =0; i < NEW_WEIGHT- 1; i++){
if (inputWeights.at(i) > maxWeight){
maxWeight = inputWeights.at(i);
}
}
cout<< "Max weight: "<< maxWeight << endl;
return 0;
}
You're making a vector of size 5:
const int NEW_WEIGHT = 5;
vector<float> inputWeights(NEW_WEIGHT);
// == 0, 0, 0, 0, 0
Then, in your input loop, you're adding new values to the end:
inputWeights.push_back (42);
// == 0, 0, 0, 0, 0, 42
Then you're outputting the first five elements which were always zero.
You need to choose one thing or the other: either set the size of the vector at the start of the program, or grow the vector with push_back for as long as there's input. Both are valid options.
You can clean up your code and fix the problems by adopting modern C++ (as in, C++11 and later) idiom. You don't need to fill your code with for(int i = 0; i < something; i++) any more. There's a simpler way.
// Size fixed in advance:
vector<float> weights(NUM_WEIGHTS);
for (auto& weight : weights) { // note it's `auto&`
cout << "\nEnter next weight: ";
cin >> weight; // if it was plain `auto` you'd overwrite a copy of an element of `weight`
}
// Size decided by input:
vector<float> weights; // starts empty this time
cout << "Enter weights. Enter negative value to stop." << endl;
float in;
while (cin >> in) {
if(in < 0) {
break;
}
weights.push_back(in);
}
In either case, you can then play with the filled vector using another range-based for:
cout << "You entered: ";
for (const auto& weight : weights) {
cout << weight << " ";
}
You'll also need to remove the cout << inputWeights[i] << endl; line from your input loop if you resize the vector during input - as written you'd be reading elements which don't exist yet, and will probably get an array-index-out-of-bounds exception.
When you create define your inputWeights you are putting 5 items into it with default values.
vector<float> inputWeights(NEW_WEIGHT);
Change it to be just
vector<float> inputWeights;
And get rid of this line in your code or comment it out
cout << inputWeights[i]<< endl;
This is what you are looking for from the requirements of your program.
#include <vector>
#include <iostream>
int main() {
std::vector<double> weights;
double currentWeight = 0.0;
const unsigned numberOfWeights = 5;
std::cout << "Enter " << numberOfWeights << " weights" << std::endl;
unsigned i = 0;
for ( ; i < numberOfWeights; ++i ) {
std::cin >> currentWeight;
weights.push_back( currentWeight );
}
std::cout << "These are the weights that you entered: " << std::endl;
for ( i = 0; i < weights.size(); ++i ) {
std::cout << weights[i] << " ";
}
std::cout << std::endl;
double totalWeight = 0.0;
std::cout << "The total of all weights is: ";
for ( i = 0; i < weights.size(); ++i ) {
totalWeight += weights[i];
}
std::cout << totalWeight << std::endl;
std::cout << "The average of all the weights is: " << (totalWeight / numberOfWeights) << std::endl;
std::cout << "The max weight is: ";
double max = weights[0];
for ( i = 0; i < weights.size(); ++i ) {
if ( weights[i] > max ) {
max = weights[i];
}
}
std::cout << max << std::endl;
return 0;
}
The culprit to your problem for seeing all 0s as output is coming from these two lines of code:
const int NEW_WEIGHT = 5;
vector<float> inputWeights(NEW_WEIGHT);
which is the same as doing this:
vector<float> inputWeights{ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
you are then looping through up to 5 elements using NEW_WEIGHT when it would be easier to use inputWeights.size() when traversing through containers.
Edit - Condensed Version
#include <vector>
#include <iostream>
int main() {
std::vector<double> weights;
double currentWeight = 0.0;
const unsigned numberOfWeights = 5;
unsigned i = 0;
std::cout << "Enter " << numberOfWeights << " weights" << std::endl;
for ( ; i < numberOfWeights; ++i ) {
std::cin >> currentWeight;
weights.push_back( currentWeight );
}
double totalWeight = 0.0;
double max = weights[0];
std::cout << "These are the weights that you entered: " << std::endl;
for ( i = 0; i < weights.size(); ++i ) {
std::cout << weights[i] << " "; // Print Each Weight
totalWeight += weights[i]; // Sum The Weights
// Look For Max Weight
if ( weights[i] > max ) {
max = weights[i];
}
}
std::cout << std::endl;
std::cout << "The total of all weights is: " << totalWeight << std::endl;
std::cout << "The average of all the weights is: " << (totalWeight / numberOfWeights) << std::endl;
std::cout << "The max weight is: " << max << std::endl;
return 0;
}

How would i make this C++ Program work with negative Numbers?

#include <iostream>
#include <vector>
using namespace std;
int main()
{
int value1; // these holds the original numbers inputted by the users
int value2;
int result;
// this holds the answer to be compared against the answer provided by using the algorithm
cout << "Please Enter the first number to be multiplied"<< endl;
cin >> value1;
cout << "Please Enter the second number to be multiplied"<< endl;
cin >> value2;
int tempnumber1 {value1}; //create a temp variable for halving while keeping main numbers stored for later use.
vector <int> halving; // this opens this vector halving which the algorithm uses
cout << "This is the Halving Step" << endl;
do
{
halving.push_back(tempnumber1);
cout <<tempnumber1 << endl;
tempnumber1/=2;
}
while (tempnumber1>0);
cout << " This is the Doubling stage" <<endl;
int tempnumber2 {value2};
for (int i=0; i<halving.size(); i++)
{
cout << tempnumber2 << endl;
tempnumber2*=2;
}
int total{0};
int doubling = value2;
for (int i =0; i < halving.size(); i++)
{
if (halving [i] %2==1)
{
cout << doubling << " Is Added to total" << endl;
total += doubling;
}
doubling *= 2; // this is used to avoid having to use two vectors.
}
//total /= 2;
result = value1*value2; // this provides the check value
cout << "The result is:" << total;
cout << "[Check Value:" << result << "]" << endl;
}
Hi, this was a university assignment from a few months ago which i passed.
The assignment was to use the russian peasant multiplication work in C++
but looking back at it, I realized that it wouldn't work with negative numbers, how would I make this program work with negative numbers?
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int value1; // these holds the original numbers inputted by the users
int value2;
int result;
// this holds the answer to be compared against the answer provided by using the algorithm
cout << "Please Enter the first number to be multiplied"<< endl;
cin >> value1;
cout << "Please Enter the second number to be multiplied"<< endl;
cin >> value2;
int tempnumber1 {value1}; //create a temp variable for halving while keeping main numbers stored for later use.
vector <int> halving; // this opens this vector halving which the algorithm uses
cout << "This is the Halving Step" << endl;
do
{
halving.push_back(tempnumber1);
cout <<tempnumber1 << endl;
tempnumber1/=2;
}
while ((tempnumber1>0 && value1>0) ||(tempnumber1<0 && value1<0));
cout << " This is the Doubling stage" <<endl;
int tempnumber2 {value2};
for (int i=0; i<halving.size(); i++)
{
cout << tempnumber2 << endl;
tempnumber2*=2;
}
int total{0};
int doubling = value2;
for (int i =0; i < halving.size(); i++)
{
if (abs(halving [i]) % 2==1)
{
cout << doubling << " Is Added to total" << endl;
total += doubling;
}
doubling *= 2; // this is used to avoid having to use two vectors.
}
//total /= 2;
result = value1*value2; // this provides the check value
cout << "The result is:" << total;
cout << "[Check Value:" << result << "]" << endl;
}
The most elegant I could think of:
cout << "This is the Halving Step" << endl;
do {
halving.push_back(tempnumber1);
cout << tempnumber1 << endl;
tempnumber1 /= 2;
} while (tempnumber1 != 0);
int total{0};
int doubling = value2;
int sign{0};
for (int i = 0; i < halving.size(); i++) {
if ((sign = halving[i] % 2) != 0) {
cout << doubling*sign << " Is Added to total" << endl;
total += doubling*sign;
}
doubling *= 2; // this is used to avoid having to use two vectors.
}
This;
while (tempnumber1>0);
Should be changed to this;
while (tempnumber1>0 || tempnumber1 < 0);
//Or
while (tempnumber1 != 0); //Thanks #besc
And this;
if (halving [i] %2==1)
Should change to this;
if (halving [i] %2==1 || halving [i] %2==-1)
//Or
if(halving[i] % 2 != 0); //Thanks #stefaanv
To accommodate negative numbers
i think you can use this(correct me if i'm wrong);
while (isdigit(tempnumber1)==0);

directed weighted graph with two weights as an adjacency matrix C++

Is this possible?
I'm making a directed weighted graph, using an adjacency matrix. Is it possible to have two weights using a matrix? I can visualize how to do this using an adjacency list, but that would entail rewriting all my code.
Here's the entirety of my code for this project. Yes, this is for school. No, I'm not asking you to do the work for me. I just can't seem to wrap my head around having two weights.
So basically, what I'm trying to do here is give the program two weights. I'll manage how to do the search and the actual cost calculations, I just can't figure out how I'm supposed to store two weights like this. The two weights are the time a train departs, and when it arrives. After that, I'll calculate the cost/path/etc. based on those two weights.
Can I have a matrix with two weights? How do I do that? I don't think a 3D matrix is what this lesson had in mind, though I think that would work (my idea being having a 3D matrix where z is just 2 deep so that I can store another integer "behind" the first one). I'd rather not, though, if possible.
As you can see, I mistook the purpose of the assignment and thought that just finding the difference between the two times and then storing that as the weight would work. But I need to know the difference between the departure of node x and the arrival of node y. So I think I need to pass those into the matrix and then calculate when I'm doing djikstra's to get the path cost.
Any ideas?
#include <iostream>
#include <iomanip>
#include <fstream>
#define MAX_SIZE 100
#define INFINITY 999999999
using namespace std;
class graph_matrix
{
public:
graph_matrix();
graph_matrix(int, int);
void setEdge(int, int, int);
void djikstra(int, int);
private:
int nodeCount;
int edgeCount;
int **matrix;
};
void graph_matrix::djikstra(int source, int destination)
{
int distances[nodeCount];
int minNode, minDistance;
bool vertexSet[nodeCount];
for(int i=0; i<nodeCount; i++)
{
distances[i] = INFINITY;
vertexSet[i] = false;
}
distances[source] = 0;
for(int i = 0; i<nodeCount-1; i++)
{
minNode = INFINITY;
minDistance = INFINITY;
for(int vert = 0; vert<nodeCount; vert++)
{
if(vertexSet[vert] == false && distances[vert] <= minDistance)
{
minDistance = distances[vert];
minNode = vert;
}
}
vertexSet[minNode] = true;
for(int vert = 0; vert<nodeCount; vert++)
{
if(vertexSet[vert] == false && matrix[minNode][vert])
{
if(distances[minNode] != INFINITY && distances[minNode] + matrix[minNode][vert] < distances[vert])
{
distances[vert] = distances[minNode] + matrix[minNode][vert];
}
}
}
}
if(distances[destination] < 60)
{
cout << distances[destination] << " minutes." << endl;
}
else if(distances[destination] > 60)
{
cout << (distances[destination] - distances[destination]%60)/60 << " hours and " << distances[destination]%60 << " minutes." << endl;
}
}
graph_matrix::graph_matrix()
{
nodeCount = 0;
edgeCount = 0;
matrix = NULL;
}
graph_matrix::graph_matrix(int nodes, int edges)
{
nodeCount = nodes + 1;
edgeCount = edges;
matrix = new int *[nodeCount];
for (int i = 0; i <= nodeCount; i++)
matrix[i] = new int[nodeCount];
for (int i = 0; i < nodeCount; i++)
{
for (int x = 0; x < nodeCount; x++)
matrix[i][x] = 0;
}
}
void graph_matrix::setEdge(int source, int destination, int weight)
{
matrix[source][destination] = weight;
}
int main()
{
ifstream file;
int statNumber, departStat, arriveStat, departTime, arriveTime, travelTime;
string statName[MAX_SIZE];
graph_matrix *gm = NULL;
file.open("stations.dat");
int stations = 0; //nodes
int tracks = 0; //edges
while(file >> statNumber)
{
file >> statName[statNumber];
stations++;
}
file.close();
file.open("trains.dat");
while(file >> departStat)
{
file >> departStat;//I tried just using 'file;' here, but it didn't work. I didn't see any harm in passing it to a variable, though.
file >> departStat;
file >> departStat;
tracks++;
//I'm sure this is the least elegant way of doing this, but this is what my brain came up with
}
file.close();
file.open("trains.dat");
gm = new graph_matrix(stations, tracks);
while(file >> departStat)
{
file >> arriveStat;
file >> departTime;
file >> arriveTime;
travelTime = arriveTime - departTime; //At first, I thought this is what I needed.
gm->setEdge(departStat, arriveStat, travelTime);
}
file.close();
int menuin, numberin, departin, arrivein;
string stationin;
bool done = false;
cout << "---------------------------------------------" << endl;
cout << " TRAIN MATE 3000 " << endl;
cout << "---------------------------------------------" << endl << endl << endl;
while(!done)
{
cout << "Options" << endl;
cout << "(1) - Look up station by number" << endl;
cout << "(2) - Look up station by name" << endl;
cout << "(3) - Find nonstop train" << endl;
cout << "(4) - Is service available" << endl;
cout << "(5) - Shortest ride time" << endl;
cout << "(6) - Quit" << endl << endl;
cout << "?: ";
cin >> menuin;
cout << endl;
switch (menuin)
{
case 1:
{
cout << ">Enter station number: ";
cin >> numberin;
cout << endl << ">>Station " << numberin << ": " << statName[numberin] << endl << endl;
break;
}
case 2:
{
cout << ">Enter station name: ";
cin >> stationin;
for(int i=0; i<=stations; i++)
{
if(stationin.compare(statName[i]) == 0)
{
cout << endl << ">>Station " << i << ": " << statName[i] << endl << endl;
}
}
break;
}
case 3:
{
cout << ">Enter departure station number: ";
cin >> departin;
cout << ">Enter arrival station number: ";
cin >> arrivein;
//do something to find if there's an edge
break;
}
case 4:
{
cout << ">Enter departure station number: ";
cin >> departin;
cout << ">Enter arrival station number: ";
cin >> arrivein;
//do something to find if there's a path
break;
}
case 5:
{
cout << ">Enter departure station number: ";
cin >> departin;
cout << ">Enter arrival station number: ";
cin >> arrivein;
cout << endl << ">>To go from " << statName[departin] << " to "<< statName[arrivein] << ", you will need to ride the train for ";
gm->djikstra(departin, arrivein);
cout << endl;
break;
}
case 6:
{
done = true;
break;
}
}
}
}
Sorry my main is pretty long. Don't worry about any of that. I'm just asking about the matrix itself, but I figured I'd give the whole context.