Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-03-2006, 12:00 PM   #1 (permalink)
Pinkfloyd
Registered User
 
Join Date: Mar 2006
Posts: 5
Pinkfloyd is on a distinguished road
displaying the greatest number

yes

Last edited by Pinkfloyd; 03-21-2006 at 10:58 AM.
Pinkfloyd is offline   Reply With Quote
Old 03-03-2006, 12:36 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
i'm not a c expert, but it would probably help you get a better answer if you described a little more about your project, like where you are going to get the data from or anything else that might help someone give you a usable solution.
sde is offline   Reply With Quote
Old 03-03-2006, 01:30 PM   #3 (permalink)
Pinkfloyd
Registered User
 
Join Date: Mar 2006
Posts: 5
Pinkfloyd is on a distinguished road
the data will be from votes that i am taking just wondering what the code would look like i mean like with adding something the code looks like
add=(jimmy page + jimmy hendrix);

or getting and average

avg = (Tes1 + Tes2 + Tes3 + Tes4 + Tes5) / 5;

kindof just looking for the set up

i know how to do greater then or less then

greater=(me<you);

hope that helps people

but i dont know how to do it with more than one
Pinkfloyd is offline   Reply With Quote
Old 03-03-2006, 01:46 PM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Store it in some form of structure, with an appropriate sort function, and let it sort according to the votes given.
Somethign like this in C would do:
Code:
#include <stdio.h>

typedef struct{
  char* name;
  int votes;
}player;

int size(player* pl);
int sort(player* pl, int size);
int show(player* pl, int size);

int main()
{
  int i;
  player pl[] = {
    {"Jimmy Page", 97},
    {"Jeff Beck", 15},
    {"Jimmy Hendrix", 105},
    {"David Gilmore", 90},
    {NULL, 0}
  }; 
  i=size(pl);
  printf("Befor sort\n");
  show(pl, i);
  if(0 < i)
    sort(pl,i);
  printf("After sort:\n");
  show(pl, i);
  return 0;
}

int size(player* pl)
{
  int i;
  if(!pl)
    return -1;
  for(i=0; NULL != pl[i].name; ++i)
    ;/* just count*/
  return i;
}
    

int show(player* pl, int size)
{
  int i;
  for(i=0; i < size; ++i)
      printf("Player:\t%s\nVotes:\t%d\n", pl[i].name, pl[i].votes);
  return 0;
}

int sort(player* pl, int size)
{
  int i,j;
  player tmp;
  for(i=0; i<size-1; i++)
    {
      for(j=0; j < size-1-i; j++)
	{
          if ( (*(pl+j)).votes > (*(pl+j+1)).votes )
	    {
             tmp = *(pl+j);
             *(pl+j) = *(pl+j+1);
             *(pl+j+1) = tmp;
	    }
	}
    }
  return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-03-2006, 01:52 PM   #5 (permalink)
Pinkfloyd
Registered User
 
Join Date: Mar 2006
Posts: 5
Pinkfloyd is on a distinguished road
thank you that helps
Pinkfloyd is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Charge account number subodhgupta1 Standard C, C++ 10 12-14-2005 07:40 AM
Stumped about a random number ... metazai PHP 4 01-11-2005 02:40 PM
Trying to get number of e-mails in a txt file to appear on my main page netpants PHP 4 08-19-2003 09:46 PM
dynamic allocation..urgent help needed!!! kashif Standard C, C++ 4 04-21-2003 09:50 AM


All times are GMT -8. The time now is 03:33 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting