| | |
I would kill for this, just a little bit
![]() |
•
•
Join Date: Oct 2004
Posts: 13
Reputation:
Solved Threads: 0
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
#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
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:
>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:
C Syntax (Toggle Plain Text)
#include <string.h> ... char name[3][20]; int myValue[3][3]; ... strcpy ( name[0], "Greg" ); myValue[0][0] = 53,000; myValue[0][1] = 5; myValue[0][2] = 1;
I'm here to prove you wrong.
•
•
Join Date: Oct 2004
Posts: 13
Reputation:
Solved Threads: 0
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.
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.
>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.
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.
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
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
IRC
Channel: irc.daniweb.com
Room: #c, #shell
•
•
Join Date: Oct 2004
Posts: 13
Reputation:
Solved Threads: 0
•
•
•
•
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
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
- 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:
Solved Threads: 0
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?
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?
![]() |
Similar Threads
- Help with Macromedia Flash! (Web Browsers)
- Can't Get Flash To Work (Windows 95 / 98 / Me)
- Search not working right... (Viruses, Spyware and other Nasties)
Other Threads in the C Forum
- Previous Thread: Im completely lost on this one
- Next Thread: pls help me in prgm of stack
| Thread Tools | Search this Thread |
* adobe ansi api array arrays binarysearch calculate centimeter char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking hardware highest homework i/o inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h






