I'm very new to c++ and I'm confused as to why my code isn't working. I feel it's an issue with the final array (array3). I don't know what though. If anyone can help out it'd be appreciated :)
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
usingnamespace std;
int main(){
int array1[5][5];
int array2[5][5];
int array3[5][5];
string infilename1, infilename2, mystring1, mystring2;
int i,j,k;
// Ask for file path and name of file
cout << "What is the file path and name of the first file?" << endl;
cin >> infilename1;
// Ask for file path and name of file
cout << "What is the file path and name of the second file?" << endl;
cin >> infilename2;
// After user gives program path file, it will find the files and opens them.
ifstream inFile1;
inFile1.open(infilename1.c_str());
ifstream inFile2;
inFile2.open(infilename2.c_str());
for(int i=0; i<5; i++){
for(int j =0; j<5; j++){
getline(inFile1, mystring1, ',');
array1[i][j] = stoi(mystring1);
cout << array1[i][j] << endl;
}
}
for( i=0; i<5; i++){
for( j =0; j<5; j++){
getline(inFile2, mystring2, ',');
array2[i][j] = stoi(mystring2);
cout << array2[i][j] << endl;
}
}
// Multiplying matrix a and b and storing in array3.
for(i = 0; i < 5; i++){
for(j = 0; j < 5; j++){
for(k = 0; k < 5; k++)
{
array3[i][j] == array1[i][k] * array2[k][j];
}
}
}
// Displaying the multiplication of two matrix.
cout << endl << "Output Matrix: " << endl;
for(i = 0; i < 5; ++i)
for(j = 0; j < 5; ++j)
{
cout << " " << array3[i][j];
}
return 0;
}
You have a == instead of = for your assignment to array3.
And you probably want some newlines between the rows of the output matrix.
Some functions wouldn't hurt, either!