User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 397,646 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 2,431 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: 1393 | Replies: 3
Reply
Join Date: Oct 2004
Posts: 13
Reputation: HollywoodTimms is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
HollywoodTimms HollywoodTimms is offline Offline
Newbie Poster

Help I just need a push!

  #1  
Oct 14th, 2004
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Location: Overflow State
Posts: 183
Reputation: Stack Overflow is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Stack Overflow's Avatar
Stack Overflow Stack Overflow is offline Offline
C Programmer

Re: I just need a push!

  #2  
Oct 14th, 2004
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:
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:
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
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
Reply With Quote  
Join Date: Oct 2004
Posts: 13
Reputation: HollywoodTimms is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
HollywoodTimms HollywoodTimms is offline Offline
Newbie Poster

Re: I just need a push!

  #3  
Oct 14th, 2004
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;
}
Reply With Quote  
Join Date: Oct 2004
Posts: 13
Reputation: HollywoodTimms is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
HollywoodTimms HollywoodTimms is offline Offline
Newbie Poster

Re: I just need a push!

  #4  
Oct 14th, 2004
Oh Crap. I also need to add names to my array before A. Is it possible to have char and int ??
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 11:02 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC