I have some experience with c++ programming in Windows (MS visual studio) and now I'm trying to experiment in Linux (I'm using the codelite).
I would like to thank personally in advance anyone who will help!!
Three issues:
1) About the main() function, should it always be int? I just ask since codelite does not accept void main()... (see also code below)
2) Codelite cannot find iostream.h, but needs #include <iostream>. Also it is always needed the using namespace std;, while ms visual studio does not.
3) Finally, I'm trying to create a program that asks user to enter the arguements of an array. Although the compiler does not find any problem, when I try to run it, it pops me out with "Program exited with return code: 255".
Below you can find my code. Any comments accepted!!!!
#include <iostream>
using namespace std;
int main() //codelite does not accept void main() (without return 0; at the //end)
{
const int n=5;
int i;
int A[n];
You are absolutely right about the for syntax. I was wondering why compiler didn't find that.
I have the visual studio 6.
Regarding the main() function, visual studio accepts it as void (without adding return 0; at the end of the program).
Hi Bazzy! Thanx for your immediate reaction! Yes, it's prehistorical!
May I ask you sth else? I'm trying to create a program that user inputs a matrix and finds the maximum value. The following code works, but there is some problem with the part (highlighted code) that is suppoded to find the max.
my code:
#include <iostream>
using namespace std;
int main()
{
const int n=3;
const int p=3;
int i,j, A[n][p];
cout <<"Enter values for 3x3 matrix A:\n";
for (i=0;i<n;i++)
{
for (j=0;j<p;j++)
{
cin >>A[i][j];
}
}
cout <<endl <<"A=\n";
for (i=0;i<n;i++)
{
cout <<endl;
for (j=0;j<p;j++)
{
cout <<" " <<A[i][j];
}
}
cout <<"\n";
max=A[0][0];
for (i=0;i<n;i++)
{
for (j=0;j<p;j++)
{
if (A[i][j]>max)
{
max=A[i][j];
}
}
}
cout <<"\nThe maximum value of A is " <<max;
Hi Bazzy. Yes I did and now the code works fine. That was the problem. Sorry for not highliting previously, I missed it.
THANKS AGAIN!
#include <iostream>
using namespace std;
int main()
{
const int n=3;
const int p=3;
int i,j, A[n][p],max;
cout <<"Enter values for 3x3 matrix A:\n";
for (i=0;i<n;i++)
{
for (j=0;j<p;j++)
{
cin >>A[i][j];
}
}
cout <<endl <<"A=\n";
for (i=0;i<n;i++)
{
cout <<endl;
for (j=0;j<p;j++)
{
cout <<" " <<A[i][j];
}
}
cout <<"\n";
max=A[0][0];
for (i=0;i<n;i++)
{
for (j=0;j<p;j++)
{
if (A[i][j]>max)
{
max=A[i][j];
}
}
}
cout <<"\nThe maximum value of A is " <<max;
cout <<endl;