1

Here is a little of my program:

struct Town
{
int population, outbreaks;
};


const int MAX_ROWS = 39;
const int MAX_COLS = 39;


void GetInfRate(Town[][MAX_COLS], int);
//some other functions


int main()
{
Town coordinates[MAX_ROWS][MAX_COLS];
//I load my data
// I display menu, etc.
}


void GetInfRate(Town c[][MAX_COLS], int MAX_ROWS)
{
//this function needs to go through the array and display
//the coordinates of those who have an infection rate
//higher than 10%. I need to output the coordinates (row
//and col and the infection rate. It has a little note to
//"traverse the entire array (2 loops), compare result >
//10". I am very confused on what traverse means.
//Here is what I have and it's not working:


int popN, outN;
double result;


for (int row = 0; row < MAX_ROWS; row++)
for (int col = 0; col < MAX_COLS; col++)
{
popN = c[row][col].population;
outN = c[row][col].outbreaks;


if (popN > 0)
result = (outbreaks / population) * 100;


if (result > 10)
{
cout<<"Row: "<<row<<endl;
cout<<"Col:  "<<col<<endl;
cout<<"Rate: "<<result<<endl;
}
}
}

What am i doing wrong?

Edited by happygeek: fixed formatting

4
Contributors
9
Replies
11
Views
12 Years
Discussion Span
Last Post by magnolia
0

Dude veg stop spamming the board it is rather annoying. You could try making your own post if you need help.
p.s: No one is going to do all the work for you sow what you have done first and we will give you tips and pointers.

0

alrite dude relax...

im not asking for all the work to be done..i just need a start on it thats all

0

magnolia please use code tags. As for your problem from what i can see it lies here

result = (outbreaks / population) * 100;

This should be

result =(c[row][col].outbreaks / c[row][col].population) * 100;
//or it could be result = (outN / popN) * 100
0

Sorry, that was my mistake. My code in my program is:

result = (outN / popN) * 100;

It doesn't work.

0

Could you possibly post your whole program?
So I could compile it and test.
Also for future please descibe what you mean by it doesn't work.

0

alrite dude relax...

im not asking for all the work to be done..i just need a start on it thats all

VeG,

Stop hijacking other people's threads. I deleted your offtopic comments from other threads, and the only reason why I'm leaving this one up is to send you a message. Please start another thread for your question, and try to write some code before posting that thread. We're not here to help you do your homework.

0

I finally found my error and got it working!! YEAH!!!

Instead of:

result = (outN / popN) * 100;

Since my outN and popN are integers and my result is a float, I needed to do this:

result = (float)(outN) / popN * 100;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.