cannot convert parameter 1 from 'std::string [12]' to 'double []'

ive been getting this error(error C2664: 'getRainfall' : cannot convert parameter 1 from 'std::string [12]' to 'double []')
since i started to code my program , and ive been trying to figure out but i coulndt find anything at all. Also, in the function it says 'name' undeclared identifer, but i identified it in the main?? can s1 explain it to me why it says undeclared identifier? and if i identify it in getRainfall function, is it gonna list name of the months?
thanks for helping...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>

using namespace std;
const int NUM_MONTHS = 12;
void getRainfall( double []);
int main()
{
	string name[NUM_MONTHS] = {"January", "February", "March",
			       "April", "May", "June",
			       "July", "August", "September",
			       "October", "November", "December"};
	
	getRainfall(name);
	
	
return 0;
}
void getRainfall( double [])
{
	
	for ( int months = 0; months < NUM_MONTHS ; months++ )
	{
		cout << "Enter the total rainfall for " << name[months] << ": ";
        cin >> name[months];
	
        
        if ( months < 0 )
		{
			cout << "The number you have entered is invalid." << endl;
			cout << "Please reenter: ";
            cin >> name[months];
		}
	
	}
	
	
	
}
You are trying to use a double when you should be using a string. Also, the error regarding 'name' not being defined is correct. There is no variable called 'name' in the getRainfall() function, only in the main() function.
1
2
3
4
5
void getRainfall( string []);
...
void getRainfall( string name[])
{
 ...

See if that works for you.
well the thing is i have an assignment and, the array must be double thats why i wrote double in prototype.
btw it didnt work at all. when i run it, it only says press any key to continue,the loop doesnt work at all.
and also if statement inside the loop doesnt work, can s1 tell me why?
Last edited on
Topic archived. No new replies allowed.