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?

Recommended Answers

All 9 Replies

hey do u know much about c++ programs

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.

alrite dude relax...

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

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

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

result = (outN / popN) * 100;

It doesn't work.

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.

It's not letting me copy and paste. Can I email it to you?

alrite dude relax...

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


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.

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;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.