Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Homework Assignment Help
Post Flair (click to view more posts with a particular flair)
Post Body

Hi,

So I've been staring at my code for a couple of hours, and I can't for the life of me figure out where I'm going wrong. I'm supposed to be making a program to determine if a 3x3 matrix is a Markov Matrix. Any help/suggestions are super appreciated. Thanks!

Here is my code:

#include <iostream>

using namespace std;

const int SIZE = 3;

bool isMarkovMatrix(const double m[][SIZE]);

int main()

{

double a\[SIZE\]\[SIZE\];

cout << "Enter a 3-by-3 matrix row by row: " << endl;

for (int i = 0; i < 3; i  )

{

    for (int j = 0; j < 3; j  )

    {

        cin >> a\[i\]\[j\];

    }

}

if (isMarkovMatrix(a))

{

    cout << "It is a Markov matrix." << endl;

}

else

{

    cout << "It is not a Markov matrix." << endl;

}

return 0;

}

bool isMarkovMatrix(const double m[][SIZE])

{

bool isMarkov = true;

for (int i = 0; i < SIZE; i  )

{

    int sum = 0;

    for (int j = 0; j < SIZE; j  )

    {

        if (m\[i\]\[j\] >= 0)

        {

sum = m[j][i];

        }

        else

        {

isMarkov = false;

        }

    }

    if (sum != 1)

    {

        isMarkov = false;

    }   

}

return isMarkov;

}

Author
Account Strength
50%
Account Age
2 years
Verified Email
Yes
Verified Flair
No
Total Karma
31
Link Karma
21
Comment Karma
10
Profile updated: 1 week ago
Posts updated: 2 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago