•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 391,774 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,440 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 1382 | Replies: 3
![]() |
•
•
Join Date: Oct 2004
Posts: 13
Reputation:
Rep Power: 4
Solved Threads: 0
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.
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.
•
•
Join Date: Sep 2004
Location: Overflow State
Posts: 183
Reputation:
Rep Power: 4
Solved Threads: 4
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[i][0]
B: myValue[i][1]
C: myValue[i][2]
As i defines 0 thru 2. If so you could take into a simple manner of arithmetic in the C language, for example: Thankfully there this mathematical syntax in C: 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: 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: 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:
So in your case, you could use a simple for loop as the following: 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
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[i][0]
B: myValue[i][1]
C: myValue[i][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;total = (myValue[0][0]/1000) + (myValue[0][1] - myValue[0][2]);
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)
statementfor (i = 0; i < 3; i++)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; }
Hope this helps,
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
•
•
Join Date: Oct 2004
Posts: 13
Reputation:
Rep Power: 4
Solved Threads: 0
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;
}
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;
}
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
Similar Threads
- Push Down Automata (PDA). (Computer Science and Software Design)
- Please review my flash CV (Website Reviews)
- Push Instruction (Assembly)
- question on Stacks push,pop. (C++)
- push ndps printer driver settings? (Novell)
Other Threads in the C Forum
- Previous Thread: Converting from VB code to C
- Next Thread: -NaN message


Linear Mode