Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,626 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,063 people online right now. Registration is fast and FREE... Join Now!




output of this code?

 
Reply to this topicStart new topic

output of this code?

duygugvn
post 28 Mar, 2006 - 01:28 PM
Post #1


New D.I.C Head

*
Joined: 31 Oct, 2005
Posts: 36


My Contributions


CODE

#include<stdio.h>
int main(void)
{
    int num;
    printf("enter a num:");
    scanf("%d",&num);
    return 0;
}

double mean(void)
{
    int x=0,n=0;
    double mean=0;
    printf("enter the numbers,a minus value to stop\n");
    while(x>=0)
    {
 printf("x:");
 scanf("%d",&x);
 mean=mean+x;
 n++;
    }
    mean=mean/n;
    return mean;
}



I did not understand this code can you explain the aim of this code and this is not work!! crazy.gif

This post has been edited by Dark_Nexus: 29 Mar, 2006 - 09:13 AM
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 28 Mar, 2006 - 02:19 PM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,176



Thanked 33 times

Dream Kudos: 25
My Contributions


The purpose is to find the aritmetic mean of a set of numbers. It likely does not work because the fucntion itself is never called from the main function.
User is offlineProfile CardPM

Go to the top of the page

duygugvn
post 29 Mar, 2006 - 07:52 AM
Post #3


New D.I.C Head

*
Joined: 31 Oct, 2005
Posts: 36


My Contributions


QUOTE(Amadeus @ 28 Mar, 2006 - 02:11 PM)
The purpose is to find the aritmetic mean of a set of numbers. It likely does not work because the fucntion itself is never called from the main function.

the aritmetic mean ????what does it mean ???
I could not understand can you explain it for me by numerical valuess! sleepy.gif
and in main; not also in this functionI did not decide to place somewhere (function call)
where I write the function call and how I understand this generally???
can you give me sourcess which helps me !:huh:
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 29 Mar, 2006 - 08:06 AM
Post #4


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,176



Thanked 33 times

Dream Kudos: 25
My Contributions


Here is an explanation of the mean...it is often referred to as the average:
http://en.wikipedia.org/wiki/Arithmetic_mean
The general process is to add all the numbers you have been given, then divide the total amount by the number of numbers.

As for the function call itself, you can place it anywhere in the main function, (remove the scanf and prompt from the main function)...then set a value equal to the return value, and voila?
CODE

double mean;
mean = mean();
printf("%f",mean);
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 03:33AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month