Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m having trouble finishing up this part of my project. I supposed have create

ID: 675096 • Letter: I

Question

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


[code]const int ARRAY_SIZE = 10.;
int a[ARRAY_SIZE];
double ma[1][2];
std::cout << "Initializing temperatures... ";
InitializeTemperatures(ma, ARRAY_SIZE);
std::cout << "Temperatures=";
PrintArray(ma, ARRAY_SIZE);
std :: cout << " ";

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;
}[/code]

Explanation / Answer

Now check with this code. It will work for you.

#include <iostream>
using namespace std;

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;
srand(time(NULL));
for (i=0; i<xSize; i++)
{
for (j=0; j<2; j++)
{
if(j==0) //inserts random numbers
ma[i][0]= rand()% 100 +1; // generates 1 to 100
else if (j==1)
ma[i][1]= (ma[i][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;
}

int main()
{
const int ARRAY_SIZE = 10.;
//int a[ARRAY_SIZE];
double ma[ARRAY_SIZE][2];
cout << "Initializing temperatures... ";
InitializeTemperatures(ma, ARRAY_SIZE);
std::cout << "Temperatures=";
PrintArray(ma, ARRAY_SIZE);
std :: cout << " ";
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote