Stupid mistake cant find!

My program keeps telling me on line 33 that it expects a (;) not a ({). i have tried countless times to get this to change since i assume that it is wrong and i cannot locate if i have an open brace. i count 16 braces with 8 of each type so im stumped. PS. this is a hw assignment but just need this one problem checked. teacher hasnt responded.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
void calculate_norm(float mine[][3]);
const int ROWS = 5;
const int COLS = 3;
int main(){
ofstream Create("problem1.txt");
int x;
for(int x = 1; x <16; x++){
Create << x << endl;
}

ifstream MyMatrix("problem1.txt");
float mine[ROWS][COLS];
cout << "Input Matrix: " << "\n" << endl;
for( int R = 0; R < 5; R++){
for( int C = 0; C < 3; C++){
MyMatrix >> mine[R][C];
}
}
for( int R = 0; R < 5; R++){
for( int C = 0; C < 3; C++){
cout << setw(6) << fixed << setprecision(2) << mine[R][C] << " ";
}
cout << endl;
cout << "\n";
}

void calculate_norm(float mine[][3]){ (this is line 33)
float R, C, max, length;
for (R = 0; R < 5; R++) {
for (C = 0; C < COLS; C++){

if (mine [0][3] > max)
max = mine [0][3];
}
//length = double sqrt(double pow(x,2) + double pow(y,2) + double pow(z,2));
}
cout << "Maximun Rows: " << max << endl;
cout << "Length: " << /*length <<*/ endl;
return;
}

MyMatrix.close();
system("pause");
return 0;
}

Last edited on
You can't define a function inside of main()
You are defining function calculate_norm inside function main. You may not do that.
So I went ahead and reworked my code to not define a function in my main. Thank you all. But now my calculate_norm function seem to now even do anything. I manipulated the code so that it will run and display the way it is supposed to but the calculations are not being performed. What may I be missing.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
float calculate_norm(float mine[][3]);
const int ROWS = 5;
const int COLS = 3;
int main(){
float length;

ofstream Create("problem1.txt");
int x;
for(int x = 1; x <16; x++){
Create << x << endl;
}
cout << "Input Matrix:" << endl;
ifstream MyMatrix("problem1.txt");
float mine[ROWS][COLS];
for( int R = 0; R < 5; R++){
for( int C = 0; C < 3; C++){
MyMatrix >> mine[R][C];
}
}
for( int R = 0; R < 5; R++){
for( int C = 0; C < 3; C++){
cout << setw(10) << fixed << setprecision(2) << mine[R][C];
}
cout << endl;
cout << "\n";}
cout << "Maximum Row : " << "4" <<endl;
cout << "Length: " << "24.29" << endl;

MyMatrix.close();
system("pause");
return 0;
}
float calculate_norm(float mine[][3]){
float R, C, max, length;
float x,y,z;
for (R = 0; R < 5; R++) {

for (C = 0; C < COLS; C++){

if (mine [0][3] > max)
max = mine [0][3];
length = sqrt(pow(x,2) + pow(y,2) + pow(z,2));
cout << max << endl;
return max;
}
}
}
 But now my calculate_norm function seem to now even do anything.

Try calling the function. And using code tags (the `<>` button) to preserve the formatting of your code.
Thanks cire and vlad. My code is fully operational now.
Topic archived. No new replies allowed.