I would kill for this, just a little bit

Reply

Join Date: Oct 2004
Posts: 13
Reputation: HollywoodTimms is an unknown quantity at this point 
Solved Threads: 0
HollywoodTimms HollywoodTimms is offline Offline
Newbie Poster

I would kill for this, just a little bit

 
1
  #1
Oct 14th, 2004
Here is what I have so far.

#include <iostream.h>

int main() {

int i, total[3];
int myValue[3][3];

myValue[0][0] = 53000;
myValue[0][1] = 5;
myValue[0][2] = 1;


myValue[1][0] = 89000;
myValue[1][1] = 3;
myValue[1][2] = 2;

myValue[2][0] = 93000;
myValue[2][1] = 3;
myValue[2][2] = 3;

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

cout << total[0] <<endl;
cout << total[1] <<endl;
cout << total[2] <<endl;




return 0;

}


I forgot a variable. I need to add a name in each of my arrays. But for some reason im getting an error saying I can't use a CHAR and a INT??? How can I do

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

When i print the result, I need the persons name to show up with the number. I been tryin to figure it out for myself for over an hour now
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,652
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 723
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: I would kill for this, just a little bit

 
0
  #2
Oct 14th, 2004
Are you so impatient as to insult everyone on this board by starting a new thread when nobody answers your followup question on the other thread? It hasn't been that long.

>I need to add a name in each of my arrays.
You're thinking about the problem wrong. You need to attach a name to the use of each array.

>myValue[0][0] = Greg;
>myValue[0][1] = 53,000;
This will never work in a language like C++. How about something more like this:
  1. #include <string.h>
  2.  
  3. ...
  4.  
  5. char name[3][20];
  6. int myValue[3][3];
  7.  
  8. ...
  9.  
  10. strcpy ( name[0], "Greg" );
  11. myValue[0][0] = 53,000;
  12. myValue[0][1] = 5;
  13. myValue[0][2] = 1;
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 13
Reputation: HollywoodTimms is an unknown quantity at this point 
Solved Threads: 0
HollywoodTimms HollywoodTimms is offline Offline
Newbie Poster

Re: I would kill for this, just a little bit

 
0
  #3
Oct 14th, 2004
My apologies on this. Now this is what i have for my output
cout << name[0] << total[0] <<endl;
cout << name[1] <<total[1] <<endl;
cout << name[2] <<total[2] <<endl;


how could i possible make this in accending order? I need the shortest first..Better yet how can it go into a priority queue? We just started on queue I understand the concept of it, but can't really put my finger on how it works.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,652
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 723
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: I would kill for this, just a little bit

 
0
  #4
Oct 14th, 2004
>I need the shortest first
The shortest name? What if they're all the same length? There's a function that you can use in the string.h header called strcmp, it returns <0, 0, or >0 depending on the relation of the first and second arguments. Working out how to print in ascending order from there is simple.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 13
Reputation: HollywoodTimms is an unknown quantity at this point 
Solved Threads: 0
HollywoodTimms HollywoodTimms is offline Offline
Newbie Poster

Re: I would kill for this, just a little bit

 
0
  #5
Oct 14th, 2004
No not the shortest name. The shortets result from total[i] execution. How could I get it into a priority queue.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 185
Reputation: Stack Overflow is an unknown quantity at this point 
Solved Threads: 4
Stack Overflow's Avatar
Stack Overflow Stack Overflow is offline Offline
C Programmer

Re: I would kill for this, just a little bit

 
1
  #6
Oct 14th, 2004
Greetings,

If I understand correctly, you want to find which of the totals are shortest. Like from minimum to maximum, e.g. A is less than B so B is greater; B is greater than C so C is less than B.

Maximum to minimum example:
B [is greater than A and C]
C [is greater than A but less than B]
A [is the least of them all]


- 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 Quick reply to this message  
Join Date: Oct 2004
Posts: 13
Reputation: HollywoodTimms is an unknown quantity at this point 
Solved Threads: 0
HollywoodTimms HollywoodTimms is offline Offline
Newbie Poster

Re: I would kill for this, just a little bit

 
0
  #7
Oct 14th, 2004
Originally Posted by Stack Overflow
Greetings,

If I understand correctly, you want to find which of the totals are shortest. Like from minimum to maximum, e.g. A is less than B so B is greater; B is greater than C so C is less than B.

Maximum to minimum example:
B [is greater than A and C]
C [is greater than A but less than B]
A [is the least of them all]


- Stack Overflow
Thats correct, but im having trouble just sorting them. I can't figure out a code to sort the total[i] in accending order
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,652
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 723
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: I would kill for this, just a little bit

 
0
  #8
Oct 14th, 2004
>I can't figure out a code to sort the total[i] in accending order
You aren't trying very hard then, are you? Sorting is a very well known classical problem in computer science. If you search for anything even related to sorting on google you'll get millions of hits.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 185
Reputation: Stack Overflow is an unknown quantity at this point 
Solved Threads: 4
Stack Overflow's Avatar
Stack Overflow Stack Overflow is offline Offline
C Programmer

Re: I would kill for this, just a little bit

 
0
  #9
Oct 14th, 2004
I agree with Narue. It may help if you search for bubble sorting. It's a famous algorithm for sorting all types of data.


- 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 Quick reply to this message  
Join Date: Oct 2004
Posts: 13
Reputation: HollywoodTimms is an unknown quantity at this point 
Solved Threads: 0
HollywoodTimms HollywoodTimms is offline Offline
Newbie Poster

Re: I would kill for this, just a little bit

 
0
  #10
Oct 14th, 2004
Ok, I looked up sorting and found qsort. I also been playing around
here is what i have

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct RECORD {
char name[20];
int num1, num2, num3;
};


int compareProduct (RECORD *rec1, RECORD *rec2)
{ return (rec1->num1 * rec1->num2) - (rec2->num1 * rec2->num2);
}


void main(void)
{
RECORD values[11] =
{ { "Brian Devaux ",53000, 5, 1 },
{ "Amanda Trapp ",89000, 3, 2 },
{ "Baclan Nguyen ",93000, 3, 3 },
{ "Sarah Gilley ",17000, 1, 4 },
{ "Warren Rexroad ",72000, 7, 5 },
{ "Jorge Gonzales ",65000, 2, 6 },
{ "Paula Hung ",34000, 3, 7 },
{ "Lou Mason ",21000, 6, 8 },
{ "Steve Chu ",42000, 4, 9 },
{ "Dave Lightfoot ",63000, 3, 10},
{ "Joanna Brown ",33000, 2, 11},


};
int i;


/* Show the original order of the records */
for (i=0; i < 11; i++)
printf ("%10s %3d %3d %3d\n",
values[i].name,values[i].num1,values[i].num2, values[i].num3);


/* now sort them based on the max product of the nums */
qsort (values,11,sizeof(RECORD),
(int (*)(const void *,const void *)) compareProduct);


/* Show the records after they're sorted */
printf ("\n\n");
for (i=0; i < 11; i++)
printf ("%10s %3d %3d %3d %4d\n",
values[i].name,values[i].num1,values[i].num2,values[i].num3,
(values[i].num1/1000) + (values[i].num2 - values [i].num3));

}

now im missing something, for some odd reason my numbers start to sort, then they dont. any help?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC