In this code I'm finding the values inside an Array using n (size of matrix) that starts with indices 1;1 (is that okay to be used?) and after the code calculates the sin (using the formula in the code) it counts the amount of positive elements in the Array.
And my question is, how do i use cout<< in a way that shows the conclusive number, instead of it counting after each value of sin?
#include < iostream >
#include < conio.h >
#include < math.h >
using namespace std;
int main ()
{
int n ;
float f ;
cout << "Kvadrat matriciin irembiig oruulnuu:" << endl ; //Энэ матриц квадрат байна. Яагаад гэвэл i,j = 1,....n.
cin >> n;
float A [n] [n] ;
for ( int i = 1 ; i < n + 1 ; i++)
{
for ( int j = 1 ; j < n + 1 ; j++)
{
f = j ;
f / = 2 ;
A [i] [j] = float ( sin ( i + f ) ) ;
cout << "[ " << i << "]" << "[" << j << "]" << A [i] [j] <<endl ;
if ( A [i] [j] > 0 )
{
int count = 0 ;
count + = count + i ;
}
}
}
return 0;
}
EDIT: because when i write the cout<< withing the loop it counts it after calculating each sin value, but outside the loop it shows an error
EDIT2:
#include < iostream >
#include < conio.h >
#include < math.h >
using namespace std;
int main ()
{
int n ;
float f ;
cout << "Kvadrat matriciin irembiig oruulnuu:" << endl ; //Энэ матриц квадрат байна. Яагаад гэвэл i,j = 1,....n.
cin >> n;
float A [n] [n] ;
for ( int i = 1 ; i < n + 1 ; i++)
{
for ( int j = 1 ; j < n + 1 ; j++)
{
f = j ;
f / = 2 ;
A [i] [j] = float ( sin ( i + f ) ) ;
cout << "[ " << i << "]" << "[" << j << "]" << A [i] [j] <<endl ;
if ( A [i] [j] > 0 )
{
int count = 0 ;
count + = count + i ;
cout << count << endl ; //this counts it after each value of sin, meaning it doesn't show one answer but multiple of them
}
cout<<count<<endl; //when i do this, it says that count wasn't declared
}
}
return 0;
}