Constant expression required problem

2 questions
1. I now the compiler i am using is outdated, Its turbo c++ version 3.0 so i want to know what changes do i need to make to make my program run on new c++ compilers
2. In line no. 10 I am getting an error:- Constant expression required. I know why it is happening but i just waana ask is there any way to get away with this problem??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int prime(int);
int t,pr;long r1,r2;
cout<<"Enter: ";
cin>>t;
long x[t][2];
for(int i=0;i<t;i++)
{
for(int j=0;j<2;j++)
{
cin>>x[i][j];
}
cout<<endl;
}
for(int k=0;k<t;k++)
{
r1=x[k][0];
r2=x[k][1];
for(int l=r1;l<=r2;l++)
{
pr=prime(r1);
if(pr==1)
cout<<pr<<endl;
}
cout<<endl;
}
getch();
}
int prime(long l)
{
long c=0;
for(long i=1;i<=l;i++)
{
if(l%i==0)
c++;
}
if(c==2)
return 1;
else
return 0;
}


i want to know what changes do i need to make to make my program run on new c++ compilers
1
2
#include<iostream.h>
#include<iostream> 
There is no iostream.h in standard C++

#include<conio.h> Avoid it. It is non-standard, outdated and often unsupported

1
2
void main()
int main()
Main shall return int. By Standard.

1
2
3
4
5
int prime(long);//←\
               //  |
int main()     //  |
{              //  |
int prime(int);// -/ 
Although declaration of functions inside functions is technically legal, do not do this. Also you have declaration mismatch definition. int and long are different

1
2
cout, cin, endl, etc...
std::cout, std::cin, std::endl, etc...


i just waana ask is there any way to get away with this problem??
1) read this article: http://www.cplusplus.com/forum/articles/17108/
2) In this concrete case vector of pairs would suit you if your compiler support it: std::vector<std::pair<long, long>>
Topic archived. No new replies allowed.