Fahrenheit to Celsius output problem

I'm having trouble finishing up this part of my project.
I supposed have created a multi dimensional array that got 10 random numbers and then treated as they were Fahrenheit then run them though the equation to get 10 other numbers in Celsius so that the output should look something like this

[45,7.22][67,19.4][21,-6.11][56,13.3]

but I it keeps coming out

[45,7.22][67,7.22][21,7.22][56,7.22]

instead I'm not sure why it's stopping


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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

// this is how i initialize the functions in the main
const int ARRAY_SIZE = 10.;
  int a[ARRAY_SIZE];
 double ma[1][2];
  std::cout << "Initializing temperatures...\n";
InitializeTemperatures(ma, ARRAY_SIZE);
std::cout << "Temperatures=";
PrintArray(ma, ARRAY_SIZE); 
std :: cout << "\n";




void InitializeTemperatures(double ma[][2], int xSize)
{
  // Develop an algorithm that inserts random numbers
  // between 1 and 100 into a[i][0]
  // hint: use rand()
  // These random numbers represent a temperature in Fahrenheit
  // Then, store the Celsius equivalents into a[i][1]
	
	
	
   int i, j;
for (i=0; i<xSize; i++)
{
for (j=0; j<2; j++)
{
if(j==0) //inserts random numbers
{
ma[i][0]= rand()% 100 +1; // print 1 to 100
}
else if (j==1)
{
ma[i][1]= (ma[0][0]-32)/1.8;
}
}}
return;
}
void PrintArray(double ma[][2], int xSize)
{
  // print the multi-dimensional array using cout
  // Each x-y pair should be printed like so: [x, y]
  // All pairs should be printed on one line with no spaces
  // Example: [x0, y0][x1, y1][x2, y2] ...

	int i;

for (i=0; i<xSize; i++)

{
std::cout << "[" << ma[i][0];
std::cout << "," << ma[i][1];
std::cout <<"]";
	
}
return;
}

Last edited on
wow thanks you fixed everything
@vinny1

Seem to me, that your array of ma on line 5, is way too small. Try changing it from
double ma[1][2];

to

double ma[ARRAY_SIZE][2];

Also, line 36, has a problem

ma[i][1]= (ma[0][0]-32)/1.8;
should be
ma[i][1]= (ma[i][0]-32)/1.8;
Last edited on
Topic archived. No new replies allowed.