I gotta write a program that reads a file and determines a customers priority number. The program then builds a priority queue using hte priority number and prints the list of people waiting. Here is what I have so far

int main() {
    int myValue[3][3];

    myValue[0][0] = 53,000;
    myValue[0][1] = 5;
    myValue[0][2] = 1;


    myValue[1][0] = 89,000;
    myValue[1][1] = 3;
    myValue[1][2] = 2;

    myValue[2][0] = 93,000;
    myValue[3][1] = 3;
    myValue[3][2] = 3;



    return 0;
}

The formula to get the priority number is A/1000 + B - C. A, B, C are shown above. Anyone give me a little push to where I should be going with this. I am a horrible programmer but I do understand the code at times.

Edited 3 Years Ago by Dani: Formatting fixed

Greetings HollywoodTimms,

Good to see you have a head-start on this. It dawned on me that I was un-aware of what you were asking specifically. I did realise you are trying to calculate A/1000 + B - C, though I was wonder what A, B, and C were. Are they according to the following?

A: myValue[0]
B: myValue[1]
C: myValue[2]

As i defines 0 thru 2. If so you could take into a simple manner of arithmetic in the C language, for example:

int total;

Thankfully there this mathematical syntax in C:

total = (myValue[0][0]/1000) + (myValue[0][1] - myValue[0][2]);

Keep in mind calling the parenthesis can help define what calculations are grouped and those which are not.

For example: 1 + 2 - 3 on your calculator may show 0 on your calculator as it performs (1+2) - (3), instead of (1) + (2-3). Either way performs 0, but what if you had 100 / 10 + 5. You must take into consideration that it may perform like so:

(100 / 10) + 5 = 15
100 / (10 + 5) = 6 2/3

Thats why in this case I used parenthesis around A/1000. Nextly, you will probably want to go through all of your myValue[] indices, stating the fact you will need to use a for loop.

The for loop
If you have not used to for loop before, it is quite simple. The for statment consists of three components; two assignment or function calls and one relational expression. The for statment syntax proves the following:

for (expr1; expr2; expr3)
	statement

This tells us that any of these three parts can be omitted though the semi-colons must remain. expr1 and expr3 are the assignment calls, while expr2 is the relational expression. The following gives a perfect expression:

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

This will set i to 0, increment i under the true condtion of i being less than 3.

We have 3 pies. If we eat one we increment, and then we are at i = 1. i is still less than 3, and as we eat another one we increment again. Now as i reaches 2, we are still less than 3. Increment again and we hit 3, the loop breaks and the program continues its normal life.

If the test, expr2, is not present, it is taken as permanetly true, so in other words stating an infinite loop presumably broken by other means, e.g. break or return:

for (;;)

So in your case, you could use a simple for loop as the following:

int main() {
	int i, total[3];
	int myValue[3][3];

	// Set myValue here

	for (i = 0; i < 3; i++) {
		total[i] = (myValue[i][0]/1000) + (myValue[i][1] - myValue[i][2]);
	}

	return 0;
}

This works as we create an integer array to hold all 3 of our new values. We took a loop until 3, and calcualated our new values. This is just a prototype version, I'm not guaranteeing it wil work the first run.


Hope this helps,
- Stack Overflow

Yeah the values for A B C are

 myValue[0][0] = 53,000;  A
myValue[0][1] = 5; B
myValue[0][2] = 1; C

Im so lost on how I put this into that code u had written. does it go like this..

int main() {
    int i, total[3];
    int myValue[3][3];

     myValue[0][0] = 53,000;
myValue[0][1] = 5;
myValue[0][2] = 1;


myValue[1][0] = 89,000;
myValue[1][1] = 3;
myValue[1][2] = 2;

myValue[2][0] = 93,000;
myValue[3][1] = 3;
myValue[3][2] = 3;

    for (i = 0; i < 3; i++) {
        total[i] = (myValue[i][0]/1000) + (myValue[i][1] - myValue[i][2]);
    }

    return 0;
}

Edited 3 Years Ago by Dani: Formatting fixed

Oh Crap. I also need to add names to my array before A. Is it possible to have char and int ??

This article has been dead for over six months. Start a new discussion instead.