473,396 Members | 2,017 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,396 software developers and data experts.

C language problem?

Hiii i am working on simple functions. and I keep getting weird syntex errors when i complie. basically i can divided them into two categories. one bunch of errors (about five or six) comes from one function body 0_o. and the second one is about using math.h.

So here is my code( its not hard to read), there is my introduction on C and that might help you going through. All the first errors come at the int input_data(double arr[], double value) block, where i try to input values and store them in array (-1 as sentiel value). Second type of error is that i get messeges that saying too many parameters in sqrt. so i made it simple enough, but it still doesnt work. Below the code are my errors.


#include <stdio.h>
#include <math.h>

int input_data(double arr[], double value);
void print_array(double arr[], int k);
void sort(double arr[], int k);
double average_function(double arr[], int k);
double sum_of_xi_x_squared(double arr[], double average, int k);

main ()
{
double arr[31], average, median1, median2, SD, mid, value;
int k, s;

printf ("Don't enter more than 30 values.\n");
printf ("Put 3 values at least, or an error messege appears.\n");
printf ("This program does following: original array, sorted array(in ascending order), average, median(s), and standard deviation.\n");
printf ("The standard deviation used in this program is SD = ( (1/n) * sigma (xi - x)^2 )^1/2, where n is the number of values, xi is each array element, and x is the average value.\n");


input_data(arr, value);
s = k;
if (s >= 3)
{
print_array(arr, s);
sort(arr, s);
average = average_function(arr, s); /* not a function?*/
printf ("the average is %.1lf.\n", average);
if (s/2 == 0)
{
median1 = arr[s/2];
median2 = arr[(s/2)-1];
printf ("The two medians are %.1lf and %.1lf.\n", median1, median2);
}
else
{
median1 = arr[s/2];
printf ("the median is %.1lf.\n", median1);
}
mid = (sum_of_xi_x_squared(arr, average, s));
SD = sqrt(mid, 1/2);
printf ("The standard deviation is %.1lf.\n", SD); /*error here*/
}
else
{
printf ("Sorry error. Less than 3 values.\n");
printf ("End of program\n");
}
printf ("The last value is %.1lf.\n", value);
return 0;
}

int input_data(double arr[], double value)
{

int k, i;
k = 0;
i = 0;

printf ("Now please enter values: \n");
scanf ("%lf," &value); /*error here*/
while (value != -1)
{
arr[i] = value;
k = k + 1;
i = i + 1;
scanf ("%lf," &value); /*error here*/
}
return k;
}

void print_array(double arr[], int s)
{
int i, n;
i = 0;
n = 1;
while ((i < 6*n) && (i < s))
{
if (i == 6*n - 1)
{
n = n + 1;
printf ("\n");
}
printf ("%.1lf", arr[i]);
i = i + 1;
}
}

void sort(double arr[], int s)
{
int i, j;
double temp;

for (i = 0; i <s - 1 ; i = i + 1)
for (j = 0; j < s - 1 - i; j = j + 1)
if (arr[j] > arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}

double average_function(double arr[], int s)
{
int i;
double sum, ave;
i = 0;
while (i < s)
{
sum = sum + arr[i];
i = i + 1;
}
ave = sum/s;
return ave;
}

double sum_of_xi_x_squared(double arr[], double average, int s)
{
int i;
double difference, sum;
i = 0;
while (i < s)
{
difference = arr[i] - average;
sum = (difference*difference) + sum;
i = i + 1;

}
return sum;
}


errors i see(please refer to /*error here*/ above :


warning C4020: 'sqrt' : too many actual parameters


'&' : illegal, left operand has type 'char [5]'
&' : illegal, right operand has type 'double '
'scanf' : too few actual parameters
( these three errors are one of the scanf error. and it repeats again for the second scanf, so i have 7 errors total)

how can i fix this?

==================================================
hold on! so i tried scanf ("%lf", value) without & in front of value,
but it still gives me errors !

syntax error : missing ')' before identifier 'value'
syntax error : ')'

but i dont see any ) missing anywhere
Nov 8 '08 #1
7 3062
weaknessforcats
9,208 Expert Mod 8TB
First, the sqrt() function has only one argument which is the number to take the square root of.

Second, when you scanf() into a double you do not need the &.

Third, your main() needs to return an int.
Nov 8 '08 #2
JosAH
11,448 Expert 8TB
Second, when you scanf() into a double you do not need the &.
Yes you do; the scanf function needs to know where it needs to store the number.

kind regards,

Jos
Nov 8 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
the scanf function needs to know where it needs to store the number.
So how come Visual Studio.NET 2008 compiles both without error?
Expand|Select|Wrap|Line Numbers
  1. double data = 0.0;
  2. scanf("%lf", &data);
  3. scanf("%lf", data);
  4.  
Nov 8 '08 #4
boxfish
469 Expert 256MB
Both ways compile fine, but without the ampersand, I get an access violation.
Nov 8 '08 #5
JosAH
11,448 Expert 8TB
So how come Visual Studio.NET 2008 compiles both without error?
Expand|Select|Wrap|Line Numbers
  1. double data = 0.0;
  2. scanf("%lf", &data);
  3. scanf("%lf", data);
  4.  
scanf() and (and its friends) is a varargs function; the compiler can't say anything
about the arguments following the format char* argument.

kind regards,

Jos
Nov 8 '08 #6
donbock
2,426 Expert 2GB
The other respondents are more intrepid than I. I didn't have the patience to try and figure out what is wrong with the OP's code. I humbly request that he put Code tags around his code so that, among other things, we see line numbers. I further request that the OP add line numbers to the provided compiler warnings (being careful to translate the line numbers so they correspond to those in the Code block). Those simple actions dramatically decrease the effort needed to find the problems.
Nov 8 '08 #7
newb16
687 512MB
You have comma inside string in scanf, like
..( "%lf, " value );
instead of
...("%lf", value );
Nov 9 '08 #8

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

Similar topics

17
by: Andreas Koch | last post by:
Hi all, i started a little "practical language comparison" - practical in the sense that i compare how actual distributions and versions and their libraries (not abstract language...
134
by: evolnet.regular | last post by:
I've been utilising C for lots of small and a few medium-sized personal projects over the course of the past decade, and I've realised lately just how little progress it's made since then. I've...
4
by: Kamen Yotov | last post by:
i have raised this question before, but i can't help it doing it again! why there is no separate newsgroup discussing the c#language, not the .net framework, visual c# etc. i am not that...
7
by: Edward Yang | last post by:
A few days ago I started a thread "I think C# is forcing us to write more (redundant) code" and got many replies (more than what I had expected). But after reading all the replies I think my...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
9
by: John Salerno | last post by:
There is an article on oreilly.net's OnLamp site called "The World's Most Maintainable Programming Language" (http://www.oreillynet.com/onlamp/blog/2006/03/the_worlds_most_maintainable_p.html). ...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
22
by: David Mathog | last post by:
One thing that keeps coming up in this forum is that standard C lacks many functions which are required in a workstation or server but not possible in an embedded controller. This results in a...
7
by: ThunderMusic | last post by:
Hi, Ok, I find myself having a lot of troubles with URL Rewriting and I've seen on the net that in some situations, indexers have difficulty indexing sites because of some flaws in the url...
27
by: notnorwegian | last post by:
(might not be the right forum for this but...) what is the definition of a highlevel-language? well there isnt one specifically and wikipedia and the like gives just a very general description...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.