Create a program that displays a table consisting of four rows and five columns. The first column should display the numbers 1 through 4. The second column and subsequent columns should display the result of multiplying the number in the first column by the numbers 2 through 5.
#include <iostream> // required header files
#include <string>
using namespace std;
int main() // driver method
{
cout << "Row and Column Data." << endl; // prompt for the user about the code
int matrix[4][5]; // array initialisation
for(int i = 1; i <= 4; i++){ // iterating over the loop of rows
for(int j = 1; j <= 5; j++) { // iterating over the loop of columns
matrix[i][j] = i*j; // setting the required data
cout << matrix[i][j] << " "; // priniting the data
}
cout << endl;
}
return(0);
}
1>------ Build started: Project: Introductory14 Project, Configuration: Debug Win32 ------
1> Introductory14.cpp
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(9): error C3872: '0xa0': this character is not allowed in an identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(9): error C2065: ' ' : undeclared identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(9): error C2143: syntax error : missing ';' before 'for'
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(10): error C3872: '0xa0': this character is not allowed in an identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(10): error C2065: ' ' : undeclared identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(10): error C2146: syntax error : missing ';' before identifier 'matrix'
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(11): error C3872: '0xa0': this character is not allowed in an identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(11): error C2065: ' ' : undeclared identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(11): error C2146: syntax error : missing ';' before identifier 'cout'
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(12): error C3872: '0xa0': this character is not allowed in an identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(12): error C2065: ' ' : undeclared identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(12): error C2143: syntax error : missing ';' before '}'
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(13): error C3872: '0xa0': this character is not allowed in an identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(13): error C2065: ' ' : undeclared identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(13): error C2146: syntax error : missing ';' before identifier 'cout'
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(14): error C3872: '0xa0': this character is not allowed in an identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(14): error C2065: ' ' : undeclared identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(14): error C2143: syntax error : missing ';' before '}'
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(15): error C3872: '0xa0': this character is not allowed in an identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(15): error C2065: ' ' : undeclared identifier
1>c:\cpp8\chap 08\introductory14 project\introductory14 project\introductory14.cpp(15): error C2143: syntax error : missing ';' before 'return'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Any suggestions on how to make a proper code that will debug
'0xa0': this character is not allowed in an identifier
0xa0 seems to be a unicode non-breaking space character. Could have happened if the code was copied and pasted into the compiler instead of being written directly there. Seems to happen first on line 9 of the code. I'd try rewriting that line by hand in the compiler and see if that takes care of that first error.
Your j loop isn't in braces, so it will actually only consist of one line. Thus, in the line cout << matrix[i][j] << " ";
the j has actually gone out of scope. I think you need to consider where you need braces around the contents of loops. From what you are doing, there are a couple of lines which need "embracing" in the j loop.
I hate to have to break this to you, but in C, C++ and related languages you count from 0. Thus, if it has size 4, the first index of your matrix will be 0,1,2,3 and not 1,2,3,4 as you have implied with your i loop. Yes, with a background in Fortran, I've done it lots of times too!
You certainly don't have to write completely new code.
(i) Put the braces in correct positions in both j AND i loops - indenting your code will help with the structure here.
(ii) You can either leave the i, j loops as they are and refer to the matrix elements (twice) as matrix[i-1][j-1] ... or you can leave the matrix[i][j] as is and change the limits of i and j loops (and the value that matrix[i][j] is assigned to) to accommodate the counting: take your pick!
Any more than that would constitute doing your homework.