473,386 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

please help me to check the code..

my problem occur when run the program is i cant enter the value that i want to in the function(float read(float x[10],y[10]).
Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5.  
  6.  main ()
  7.  {
  8.   float read(float x[10],float y[10]);
  9.   float calculate_A(float x0,float y0);
  10.  
  11.  
  12.  
  13.       float a,b;
  14.       float x[10];
  15.       float y[10];
  16.       float x0,x1,x2,y0,y1,y2;
  17.       a=x0,b=y0;
  18.  
  19.       printf("the mean value for x is %f",a);
  20.       printf("the mean value for y id %f",b);
  21.  
  22.  
  23.       getch();
  24.       }
  25.  
  26.       loat read(float x[10],float y[10])
  27.       { int n,i;
  28.        float x0,y0;       
  29.        float x[10],y[10];
  30.  
  31.  
  32.       puts("enter the number of data(n):\n");
  33.       scanf(" %d",&n);
  34.       puts("enter the values for x:\n");
  35.       for(i=0;i<=9;i++)
  36.       {scanf(" %f",&x[10]);}
  37.       puts("enter the values for y:\n");
  38.       for(i=0;i<=9;i++)
  39.       {scanf(" %f",&y[10]);}
  40.       return ;
  41.        //system("pause");
  42.       }
  43.       float calculate_A(float x0,float y0)
  44.       {
  45.             int n,sum1,sum2,sum;
  46.  
  47.             float x[10],y[10];
  48.             sum1=sum+x[10];
  49.             x0=sum1/n;
  50.             sum2=sum+y[10];
  51.             y0=sum2/n;
  52.             printf("%f",x0);
  53.             printf("%f",y0);
  54.             return(x0,y0);
  55.             }
  56.  
  57.       //system("pause");
Apr 10 '10 #1
3 1301
weaknessforcats
9,208 Expert Mod 8TB
It looks like a confusion on the two arrays and and y. You have them defined in every function. I would expect you define them once in main and then call your functions using the addresses of the arrays:

Expand|Select|Wrap|Line Numbers
  1. float x[10];
  2. float y[10];
  3.  
  4.  
  5. MyFunc(x, y, 10, 10);
where:

Expand|Select|Wrap|Line Numbers
  1. void MyFunc(float* a, float* b, int numelements_x, numelements_y)
  2. {
  3.      Here a[1] is the same as x[1] in main.
  4. }
You need to pass in the number of elements since the name of an array is the address of element 0 and from inside the function all you can see is this address. The number of elements in the array hhas been lost. This is called
Expand|Select|Wrap|Line Numbers
  1. decay of arra
y and is just a thing to live with.

Be sure to call your functions after the arrays are defined in main().
Apr 10 '10 #2
thank u weaknessforcats..i have one question to ask u...how i suppose to send a value from a function to a function???i cannot send the values that i enter from the first function to another function...can you help me to check the code...thank you...
Expand|Select|Wrap|Line Numbers
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<math.h>
  4. float read(void);
  5. void calculate(float*sum1,float*sum2);
  6. main ()
  7.  
  8. {     float a,b,sum1,sum2;
  9.     read();
  10.  
  11.      printf("%f",&sum1);
  12.      printf("%f",&sum2);
  13.      system("pause");
  14.   }
  15.      float read(void)
  16.      {
  17.            int n,i;
  18.            float x[10],y[10];
  19.            puts("please enter a value of n:\n");
  20.            scanf("%d",&n);
  21.            puts("please enter the values for x:\n");
  22.            for(i=0;i<n;i++)
  23.            {scanf("%f",&x[i]);}
  24.  
  25.            puts("please enter the values for y:\n");
  26.            for(i=0;i<n;i++)
  27.            {scanf("%f",&y[i]);}
  28.            return((x[i],y[i]));
  29.            }
  30.            void calculate(float *sum1,float*sum2)
  31.            {
  32.  
  33.                 int n,i;
  34.                 float x[i],y[i];
  35.                 float sum=0;
  36.                 read();
  37.                 *sum1=(sum+x[i]/n);
  38.                 *sum2=(sum+y[i]/n);
  39.                 }
Apr 11 '10 #3
weaknessforcats
9,208 Expert Mod 8TB
Please remember that a function when has completed executing, that is, when it returns, is an instance of its return type. That is,

Expand|Select|Wrap|Line Numbers
  1. int MyFunc();
MyFunc() becomes an int if you execute it. SO this code:

Expand|Select|Wrap|Line Numbers
  1. int y = MyFunc();
is prefectly OK becuase the compiler knows that by calling MyFunc() it will get the correct int value to assign to y. So this code:

Expand|Select|Wrap|Line Numbers
  1. void AnotherFunc(int arg);
  2.  
  3. AnotherFunc(MyFunc());
is also OK. The compiler knows that by calling MyFunc() it eill get the int value to supply to the arg argument of AnotherFunc.

This is NOT OK:

Expand|Select|Wrap|Line Numbers
  1. void Func();
  2.  
  3. int y = Func();
void means "no type". Here the compiler knows that by calling Func() that nothing will be returned so there will be nothing to initialize y. In this case ytou get a compile-time error.
Apr 11 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

35
by: wired | last post by:
Hi, I've just taught myself C++, so I haven't learnt much about style or the like from any single source, and I'm quite styleless as a result. But at the same time, I really want nice code and I...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
1
by: Pax S | last post by:
I need a button that will check (make true) two check boxes (fields) For the record that has the focus (the record on the form that I am presently looking at). The two check boxes would be like a...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
4
by: Gary | last post by:
Hello, I'm hoping someone can shed some light on why my report does not output the same results as shown in preview mode, which is to move the position of a check box based on a field value (see...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
1
by: icetalks | last post by:
have a look at this code , its for logging the user in after checking his UserName and Password. dim check as boolean = false ... ... If txtUserName.Text.Length = 0 And txtPass.Text.Length =...
5
kirubagari
by: kirubagari | last post by:
I want to check the arrangement of data in this order from byte 49 to mFile size(END OF FILE). 04 FF _ _ _ _ _04 FF _ _ _ _ 04 FF _ _. _ __ 04 FF _ _ _ _ 04 FF _ _ _ _ 04 FF Actually the values...
61
by: warint | last post by:
My lecturer gave us an assignment. He has a very "mature" way of teaching in that he doesn't care whether people show up, whether they do the assignments, or whether they copy other people's work....
2
by: LilMeechc20 | last post by:
Hello, I have a group assignment that I have to do. We have to write a Tic Tac Toe game. One person in my group has managed to write the code for a multiplayer (human -vs- human) game and I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.