iSTORYA.NET

Go Back   iSTORYA.NET > Technology > Software & Games > Programming
: :

Register FAQ Members List Calendar Mark Forums Read

Programming :: Programming related discussions ::

Reply
LinkBack Thread Tools
  #1  
Old 08-30-2008, 09:42 AM
Newbie
pau_liniment is offline
Join Date: Aug 2008
Posts: 5
Exclamation to all programmers out there... I NEED HELP XD

yo! nid help on this..
i'm still a newbie in this kind of business..
i want to see how you make a code out of this and compare it to my own..
or i can send you a copy of my code and correct it for my benefit XD..
just reply to this post with your e.mail!
thanks!

C/C++..... nid help! XD

here's the prob anyways....

Write a program that reads 7 scores as input and outputs the average. The program uses an array of floats. Note that you need to determine the highest and the lowest score and exclude them in the computation, assume that there are no judges giving the same score.

list of scores that the judges give:
9.20
9.00
8.75
9.40
9.50
8.90
9.60

/* you can use functions on this */

/* the output would similarly look like this */

Enter the 7 scores: 9.20 9.00 8.75 9.40 9.50 8.90 9.60

Highest score: 9.60

Lowest score: 8.75

Average score: 9.20
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 08-30-2008, 04:23 PM
Elite Member
silent-kill is offline
silent-kill's Avatar
Join Date: Mar 2003
Posts: 1,662
Send a message via Yahoo to silent-kill
Default

your just being lazy, why did you even take up CS/IT if you dont like solving problems?.

that like what you learn in gradeschool adding averaging numbers.

remember this is the fundamental concepts you'll need to learn if you want to survive in the real world LOL LOL
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 08-30-2008, 04:30 PM
Junior Member
MarkCuering is offline
Join Date: Aug 2008
Posts: 360
Default

and here comes with 2 post... OMG.... ^^ what a day hahehhehehehe
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 08-30-2008, 05:01 PM
Newbie
larrysbird is offline
Join Date: Aug 2008
Posts: 24
Default

I can do this but using PHP T_T. I tried C++ b4 but t'was a very long time ago . Ok lang ang PHP? But anyways the logic will be like this.


PHP Code:
$arrayinputs = array(9.209.008.759.409.508.909.60); // given inputs

$size count($arrayinputs);  // count the number of elements.

// initialize some variables.

$elementholder 0

$average 0.0;

$lowest 0;

$highest 0;

// use loop to process each elements of $arrayinputs.

for ( $i=0$i<$size$i++) {

    if(
$i==0){

        
// inialized the first max and min.
        
        
$highest $arrayinputs[$i];

        
$lowest $arrayinputs[$i];

    }

    if (
$arrayinputs[$i]>$highest){

        
$average += $highest// add the previous highest if new highest is found


        
$highest $arrayinputs[$i]; // replace the old highest

    
}elseif ($arrayinputs[$i]<$lowest){
        
        if(
$lowest!=$highest){ // this if is necessary since $lowest = $highest during the first loop avoiding duplicate addition.

            
$average += $lowest// add the previous lowest if new lowest is found

        
}

        
$lowest $arrayinputs[$i]; // replace the old lowest

    
}elseif($arrayinputs[$i]>$lowest && $arrayinputs[$i]<$highest) {

        
$average += $arrayinputs[$i]; // otherwise just add them.

    
}

}

print_r('average: '.$average/($size-2)); // $size-2 since max and min is excluded. 
Only valid if all inputs are entered prior processing.

regards,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 08-30-2008, 05:59 PM
Junior Member
MarkCuering is offline
Join Date: Aug 2008
Posts: 360
Default

Code:
L = [9.20, 9.00, 8.75, 9.40 ,9.50, 8.90, 9.60]
     
for x, num in enumerate(L):
    if not x: low = num
    if num >= low: high = num
    if num < low: low = num
    if num > high: high = num
    
print "Highest: ", high
print "Lowest: ", low
print "Average: ", sum(L) / len(L)
Highest: 9.6
Lowest: 8.75
Average: 9.19285714286


though I could use the .sort() and index it with len functions.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 08-30-2008, 10:01 PM
Elite Member
ChaosOrb is online now
ChaosOrb's Avatar
Join Date: Oct 2003
Gender: Male
Posts: 1,323
Send a message via ICQ to ChaosOrb Send a message via AIM to ChaosOrb Send a message via MSN to ChaosOrb Send a message via Yahoo to ChaosOrb Send a message via Skype™ to ChaosOrb
Default

OT: wow, another assignment thread! what a day indeed! Katawa nlng ta ani Mark? ^_^

the code is above, just in PHP format, convert it to C++.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7  
Old 08-30-2008, 10:11 PM
Junior Member
MarkCuering is offline
Join Date: Aug 2008
Posts: 360
Default

mine is in python ^^ hahahahaha
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8  
Old 08-30-2008, 11:31 PM
Newbie
pau_liniment is offline
Join Date: Aug 2008
Posts: 5
Default

hehehe!! u guys don't read that much don't you?..


Quote:
Originally Posted by pau_liniment
or i can send you a copy of my code and correct it for my benefit XD..
just reply to this post with your e.mail!
what's wrong on searcing for a good reference or a mentor?>..

sorry again for the trouble...

ps: thanks anyway for those who gave there ideas...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9  
Old 08-30-2008, 11:52 PM
Newbie
bordogoy is offline
Join Date: Aug 2008
Posts: 16
Default

try to analyze the problem and make ur own program so that it will be just checked and you can also learn something...LOL
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10  
Old 08-31-2008, 01:36 AM
Newbie
wildfrog is offline
Join Date: Jun 2008
Posts: 19
Default

Quote:
Originally Posted by silent-kill View Post
your just being lazy, why did you even take up CS/IT if you dont like solving problems?.

that like what you learn in gradeschool adding averaging numbers.

remember this is the fundamental concepts you'll need to learn if you want to survive in the real world LOL LOL
sakto si silent kill...bro imo man ko gipakatawa

epa email pa niya
paul its so basic, jut keep on reading and practice.......
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11  
Old 08-31-2008, 01:39 PM
Newbie
pau_liniment is offline
Join Date: Aug 2008
Posts: 5
Default

heheh!!. sorry... i'll just show you my code and... just help me where are my mistakes..
thanks again.. and sorry for the trouble...

#include <stdio.h>
#define N 7
void input (float a[], int N);
float highest (float a[], int N);
float lowest (float a[], int N);
float average (float highest, float lowest, float a[], int N);

int main (void)
{
float a[N];
float Highest, Lowest, Average;

input (a[], N);
Highest = highest (a[], N);
Lowest = lowest (a[], N);
Average = average (Highest, Lowest, a[], N);
printf ("Highest : %.2f", Highest);
printf ("Lowest : %.2f", Lowest);
printf ("Average : %.2f", average);

}

void input (float a[], int N)
{
int i;
prinf("Enter the scores of 7 judges:");
for (1=0; i<N; i++)
scanf ("%f", &a[i]);
}

float highest (float a[], int N)
{
int i;
float highest;
highest=a[o];
for (i=1; i<n; i++)
if (highest<a[i])
highest=a[i];

return highest;
}

float lowest (float a[], int N)
{
int i;
float lowest;
lowest=a[0];
for (i=1; i<N; i++)
if (lowest>a[i])
lowest = a[i];

return lowest;
}

float average (float highest, float lowest, float a[], int N)
{
int i;
float highlow, ave, x;
highlow = highest + lowest;
for (i=0; i<N; i++)
sum = sum + a[i];
x = sum - highlow;
ave = x/5.0;

return ave;
}

ps: i've minimized the errors in my code
please HELP me on this i need it working ASAP!..

Error C:\tc2\projecti.c 3: Declaration syntax error
Error C:\tc2\projecti.c 4: Declaration syntax error
Error C:\tc2\projecti.c 5: Declaration syntax error
Error C:\tc2\projecti.c 6: Declaration syntax error
Error C:\tc2\projecti.c 13: Expression syntax in function main
Error C:\tc2\projecti.c 14: Expression syntax in function main
Error C:\tc2\projecti.c 15: Expression syntax in function main
Error C:\tc2\projecti.c 16: Expression syntax in function main
Warning C:\tc2\projecti.c 17: posible use of 'Higest' before definition in function main
Warning C:\tc2\projecti.c 18: posible use of 'Lowest' before definition in function main
Error C:\tc2\projecti.c 23: Declaration syntax error
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12  
Old 08-31-2008, 02:18 PM
Elite Member
silent-kill is offline
silent-kill's Avatar
Join Date: Mar 2003
Posts: 1,662
Send a message via Yahoo to silent-kill
Default

input (a, N);
Highest = highest (a, N);
Lowest = lowest (a, N);
Average = average (Highest, Lowest, a, N);

mao man basin na. hahaaha
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13  
Old 08-31-2008, 03:27 PM
Junior Member
nebulom is offline
Join Date: Apr 2008
Posts: 31
Default

I'm not too sure about the logic but here goes. I've removed all your errors about N and n. Something like o and 0. I'm not practicing C++ by profession so I'm not sure about what you did in school but using Turbo C is quite old. Visual C++ 2003 and up is complaint to standard 99. Or better yet the GNU Compilers are good.

There is also an upcoming standard for C++ by ANSI (I think) this coming 2009. I just don't know the details. Anyway, here's your code. And oh, please use [code][/code] when posting code.

Code:
#include <stdio.h>
#define N 7

void input(float a[], int n) {
	printf("Enter the scores of 7 judges: ");
	for (int i = 0; i < n; i++) {
		scanf("%f", &a[i]);
	}
}

float highest (float a[], int n) {
	int i;
	float highest;
	highest=a[0];
	for (i=1; i<n; i++)
	if (highest<a[i])
	highest=a[i];

	return highest;
}

float lowest (float a[], int n) {
	int i;
	float lowest;
	lowest=a[0];
	for (i=1; i<n; i++)
	if (lowest>a[i])
	lowest = a[i];

	return lowest;
}

float average (float highest, float lowest, float a[], int n) {
	int i;
	float highlow, ave, x, sum = 0;
	highlow = highest + lowest;
	for (i=0; i<n; i++)
	sum = sum + a[i];
	x = sum - highlow;
	ave = x/5.0;

	return ave;
}

int main() {
	float a[N];
	float Highest, Lowest, Average;

	input (a, N);
	Highest = highest (a, N);
	Lowest = lowest (a, N);
	Average = average (Highest, Lowest, a, N);

	printf ("Highest : %.2f", Highest);
	printf ("Lowest : %.2f", Lowest);
	printf ("Average : %.2f", Average);

	return 0;
}
There are still warnings though and I don't bother solving them. I used VC2005 so you might want to convert it if anything goes wrong with Turbo C.

Best Regards!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14  
Old 08-31-2008, 03:52 PM
Newbie
pau_liniment is offline
Join Date: Aug 2008
Posts: 5
Default

:eek:so you can make a program in this manner......
quite confussed on the arrangement.. *heheheh* but it's ok..
thanks for the correction... hehehe compiling it now.....


one more thing.... how about the prototype?> is it ok not to place a function prototype??..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15  
Old 08-31-2008, 03:56 PM
Junior Member
nebulom is offline
Join Date: Apr 2008
Posts: 31
Default

Quote:
Originally Posted by pau_liniment View Post
:eek:so you can make a program in this manner......
quite confussed on the arrangement.. *heheheh* but it's ok..
thanks for the correction... hehehe compiling it now.....


one more thing.... how about the prototype?> is it ok not to place a function prototype??..
Yes it is. As a small code, you don't actually do prototyping.

Digg this Post!Add Post to del.icio.usBookmark Post in Technorati