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

Can someone tell me whats wrong with my code. It keeps saying ma is a undeclared

ID: 674348 • Letter: C

Question

Can someone tell me whats wrong with my code. It keeps saying ma is a undeclared variable and wont compile.

#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <ctime>
#include <cstdlib>

void InitializeTemperatures(double ma[][2], int xSize);
void Array(double ma[][2], int xSize);

int main()
{

cout << "Initializing temperatures..."<< endl;

    InitializeTemperatures(ma, ARRAY_SIZE);

   cout << "Temperatures=";
   Array(ma, ARRAY_SIZE);

   cout << "Temperatures(F, C)=" << endl;
   Array(ma, ARRAY_SIZE);

cout << "Press ENTER";
cin.ignore();
cin.get();
return 0;
}

void InitializeTemperatures(double ma[][2], int xSize)
{
for( int i = 0; i < xSize; i++)
{
   for(int j = 0; j < xSize; j++)
   {
       ma[i][j]= rand() % 100 + 1;

   }
   }
}


void Array(double ma[][2], int xSize)
{
for(int i=0; i < xSize; i++)
{
   for(int k = 0; k < 2; k++)
       ma[i][k];
}
}

Explanation / Answer

#include <iostream>

#include <vector>

#include <string>

#include <iomanip>

#include <ctime>

#include <cstdlib>

using namespace std;

void InitializeTemperatures(double ma[][2], int xSize);

void Array(double ma[][2], int xSize);

int main()

{

int ARRAY_SIZE = 10;

double ma[ARRAY_SIZE][2];

cout << "Initializing temperatures..."<< endl;

InitializeTemperatures(ma, ARRAY_SIZE);

cout << "Temperatures=";

Array(ma, ARRAY_SIZE);

cout << "Temperatures(F, C)=" << endl;

Array(ma, ARRAY_SIZE);

cout << "Press ENTER";

cin.ignore();

cin.get();

return 0;

}

void InitializeTemperatures(double ma[][2], int xSize)

{

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

{

for(int j = 0; j < xSize; j++)

{

ma[i][j]= rand() % 100 + 1;

}

}

}

void Array(double ma[][2], int xSize)

{

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

{

for(int k = 0; k < 2; k++)

cout << ma[i][k];

}

}

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