473,223 Members | 1,720 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,223 software developers and data experts.

error: cannot convert `float' to `float*' for argument `1' to `f

Hi,
I'm trying to write a program using the Dev C++ 4.9.9.2 compiler that takes input numbers from a word document, sums them together, and then gives me a result. It should be easy as the book I have tells me what to do, problem is I get the error message
"cannot convert `float' to `float*' for argument `1' to `float array_sum(float*, int)' " for line 22 of the program. This is what I have;

#include <iostream.h>
#include <fstream.h>

float array_sum(float c[100], int m);

int main()
{
float a[100];
int n;
float sum; //b[100];
ifstream read("C:\\Dev-Cpp\\numbers one to one hundred.doc");
if(!read)
{
cout << "input file failed to open";
system ("pause");
exit(1);
}
while(!read.eof())
{
read >> a[100];
}
sum = array_sum(a[100],m);
cin >> n;
cout << "a sum = " << sum << endl;
read.close();
system ("pause");
}

please keep your replies simple, I'm still quiet new to the whole programming thing.
Pixie
Jul 3 '06 #1
4 24895
I should have said the numbers I was extracting from word were just 1 to 100, in order, with no repetition
Pixie
Jul 3 '06 #2
D_C
293 100+
Line 22:
sum = array_sum(a[100],m);

First, a[100] is the 100th entry of array a, which is 100(float) according to you. Second, arrays cannot be passed all at once. It's looking for a pointer to the array. Change Line 22 so it now uses the address of a, instead of the 100th element of array a. Also make the appropriate updates to array_sum function so the first argument is a pointer to an array of floats.

sum = array_sum(&a,m); // Should give the starting address of array a

Also, I did not see where m was defined. I am assuming it's 100, the length of a. Generally if you pass an array by address, it only knows the starting address, not how many elements there are in it. A character array might be the exception, as it should have the null string terminator at the end, and it should know where to stop. That's not always the case though.
Jul 3 '06 #3
Banfa
9,065 Expert Mod 8TB
Hope you don't mind D_C most of what you say is true but...

First, a[100] is the 101st entry of array a, and in this example an out of bounds access as a only has 100 entries.

&a is not a good way to get the address of a, it has type float (*)[100]. More usual would be just a or &a[0] which are both of type float *. It should be noted that all these expressions will access the same location in memory, however you have no garunttee from the C standard that

&a == &a[0]

because a give platform could have a different notation for holding pointer to array and pointer to float.

Since normally you would declare the called function

void fn( float *InArray );

you want to pass a variable of type float *. Some compilers will issue a warning if you pass &a to fn.
Jul 3 '06 #4
thanks for the help, its pretty well working now but I have to toy with it so it doesn't freeze when the numbers get too large. In case anyone is interested this is what i currently have.
-------------------------------------------------------------------------------------------------------------------------
#include <iostream.h>
#include <fstream.h>
int main()
{
int m, j;
float a[100], sum[m], A;
cout << "the value of m is ";
cin >> m;
ifstream read("C:\\Dev-Cpp\\numbers one to one hundred.doc");
ofstream prt("C:\\Dev-Cpp\\summed one to one hundred.doc", ios::trunc);
if(!read)
{
cout << "input file failed to open";
system ("pause");
exit(1);
}
if(!prt)
{
cout << "output file failed to open";
system ("pause");
exit(1);
}
sum[0] = 0;
for (j = 0; j <= m; j++)
{
cout << "a[" << j << "] = " << A << "\n";
prt << "a[" << j << "] = " << A << " ";
read >> A;
cout << "a sum = " << sum[j] << endl;
prt << "a sum = " << sum[j] << endl;
sum[j+1] = sum[j] + A;
}
read.close();
system ("pause");
}

Pixie
Jul 4 '06 #5

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

Similar topics

8
by: codefixer | last post by:
Hi, Why do I get this error ? 'CRectangle::CRectangle' : ambiguous call to overloaded function Thanks in advance. #include <iostream.h>
6
by: bluekite2000 | last post by:
I have Vector<complex<float> > V(5); V.rand(); Vector<float> V1(V); //specialized function here to return norm(V). This works fine Vector<double> V2(5); V2.rand(); Vector<float>...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
9
by: i | last post by:
#include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> char ch; int n,m; void main(); char check(int,int,char); void cash(int,int,char); void debit_card(int,int,char);
22
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float...
11
by: Gary James | last post by:
I'm using an object data type variable to pass a numeric value (Int, Float, Double, etc) to a function that returns a formatted string. However, nullable types do not provide an overridden...
2
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $...
8
by: Ruben | last post by:
error: passing `const Weight' as `this' argument of `float Weight::wgt()' discards qualifiers seems to be some sort of standard error format that I'm not understanding. I have code that...
9
by: Marco Nef | last post by:
Hi there I'm looking for a template class that converts the template argument to a string, so something like the following should work: Convert<float>::Get() == "float"; Convert<3>::Get() ==...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.