C++ programming in ubuntu Linux

Hello guys,

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];

for (i=0;i++;i<n)
{
cin >>A[i]; //value input
}

for (i=0;i++;i<n)
{
cout <<A[i]; //value output
}

return 0;
}
1) main must be declared to return int.

2) Which version of visual studio are you using? iostream.h is pre-standard C++

3) You have messed up the for. It should be for (i=0;i<n;i++) ( swap condition and increment )

http://www.cplusplus.com/doc/tutorial/control/#for
Hi Bazzy!

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).

Thanks you very much for replying.
Visual studio 6 is ancient. No wonder it accepts non-standard C++
( IIRC VS6 was released the same year as the ISO C++ standard )

for (i=0;i++;i<n) Is actually correct in C++, but it doesn't do the same as for (i=0;i<n;i++) would
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;

return 0;
}
Please use [code][/code] tags

Did you declare 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;

return 0;
}
Topic archived. No new replies allowed.