YOUR CODE'S OUTPUT 1 did not compile/run! ----- 2 10 2 10 12 14 16 18 20 12 15 18 24 27 30 4 12 16 20 24 28 32 36 40 10 15 20 25 30 35 40 45 50 12 18 24 30 36 42 48 54 60 14 21 28 35 42 49 56 63 70 10 16 24 32 40 48 56 64 72 80 11 18 27 36 45 54 63 72 81 90 12 10 20 30 40 50 60 70 80 90 100 13 11 22 33 44 55 66 77 88 99 110 14 12 24 36 48 60 72 84 96 108 120 timeout: the monitored command dumped core 16 | ERROR 15 ] the program Aborted (core dumped) (SIGABRT) THE CORRECLOUTPUT OF THE TEST CAS
Getting an error when I run my c++ code
The directions for the hw was to
Create a multiplication table:
row from 1 to 12
column from 1 to 10
First, populate the multiplication table using a 2D array.
Print out the contents of the multiplication table.
My code:
#include<iostream>
#include<iomanip> //include for using setw
using namespace std;
//define a constant COL_SIZE
const int COL_SIZE = 10;
// prototyping of the functions
void createTable(int array[][COL_SIZE], int rowSize);
void printTable (int array[][COL_SIZE], int rowSize, int columnWidth);
// the main method
int main()
{
//define constants
const int ROW_SIZE = 12;
const int COL_WIDTH = 6;
//define 2D array with rowssize= 12 and columnsize=10
int multArray[ROW_SIZE] [COL_SIZE];
//call the fuction createTable()
createTable(multArray, ROW_SIZE);
//call the function printTable()
printTable(multArray, ROW_SIZE, COL_WIDTH);
return 0;
}
//method for crating table
void createTable(int array[][COL_SIZE], int rowSize)
{
//using nested for loop to create table
for(int i=1;i<=rowSize;i++)
{
//inner for loop
for(int j=1;j<=COL_SIZE;j++)
{
//multiply the numbers
array[i][j]=i*j;
}
}
}
//define the method to print table
void printTable (int array[][COL_SIZE], int rowSize, int columnWidth)
{
//printing the table using nested loop
for(int i=1;i<=rowSize;i++)
{
//inner for loop
for(int j=1;j<=COL_SIZE;j++)
{
//print the array elements
cout<<setw(columnWidth)<<array[i][j]; //set the width using columnwidth and print the table
}
// for new line
cout<<endl;
}
}
Below I have attached the error I get
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images