im using microsoft visual studio 2010.
Code:
int year2010[]={3230,541,1305,700}; int year2011[]={3257,532,1394,702};
int year2012[]={3285,533,1494,705};
int year2013[]={3313,531,1554,708};
int year2014[]={3343,527,1598,718};
this are the extern int
Code:
#include<stdio.h>
void main(void)
{
char selection;
extern int year2010[],year2011[],year2012[],year2013[],year2014[];
int totalPopulation, ratioOfResident, pop2010, pop2011,pop2012,pop2013,pop2014,choice,selection1;
selection1 = 0;
do{
printf("MENU\n");
printf("-----\n");
printf("1-Population of 2010\n");
printf("2-Population of 2011\n");
printf("3-Population of 2012\n");
printf("4-Population of 2013\n");
printf("5-Population of 2014\n");
printf("Please select 1,2,3,4 or 5:");
scanf(" %c",&selection);
}while(selection <1 || selection >5);
switch(selection)
{
case'1':
do{
printf("1-Number of citizen in thousands\n");
printf("2-Number of PR(resident) in thousands\n");
printf("3-Number of non-resident in thousands\n");
printf("4-Land area(sq.km.)\n");
printf("Please select 1,2,3,4: \n");
scanf("%d",&choice);
if(choice == 1)
printf("Number of citizen(resident) is %d.\n",year2010[0]);
else if(choice == 2)
printf("Number of PR(resident) in thousands is %d.\n",year2010[1]);
else if(choice == 3)
printf("Number of non-resident in thousands is %d.\n",year2010[2]);
else if(choice == 4)
printf("Land area(sq.km.) is %d.\n",year2010[3]);
else
printf("You have select a wrong choice.\n");
}while(choice<1 || choice>4);
break;
case'2':
do{
printf("1-Number of citizen in thousands\n");
printf("2-Number of PR(resident) in thousands\n");
printf("3-Number of non-resident in thousands\n");
printf("4-Land area(sq.km.)\n");
printf("Please select 1,2,3,4: \n");
scanf("%d",&choice);
if(choice == 1)
printf("Number of citizen(resident) is %d.\n",year2011[0]);
else if(choice == 2)
printf("Number of PR(resident) in thousands is %d.\n",year2011[1]);
else if(choice == 3)
printf("Number of non-resident in thousands is %d.\n",year2011[2]);
else if(choice == 4)
printf("Land area(sq.km.) is %d.\n",year2011[3]);
else
printf("You have select a wrong choice.\n");
}while(choice<1||choice>5);
break;
case'3':
printf("1-Number of citizen in thousands\n");
printf("2-Number of PR(resident) in thousands\n");
printf("3-Number of non-resident in thousands\n");
printf("4-Land area(sq.km.)\n");
printf("Please select 1,2,3,4: \n");
scanf("%d",&choice);
if(choice == 1)
printf("Number of citizen(resident) is %d.\n",year2012[0]);
else if(choice == 2)
printf("Number of PR(resident) in thousands is %d.\n",year2012[1]);
else if(choice == 3)
printf("Number of non-resident in thousands is %d.\n",year2012[2]);
else if(choice == 4)
printf("Land area(sq.km.) is %d.\n",year2012[3]);
else
printf("You have select a wrong choice.\n");
break;
case'4':
printf("1-Number of citizen in thousands\n");
printf("2-Number of PR(resident) in thousands\n");
printf("3-Number of non-resident in thousands\n");
printf("4-Land area(sq.km.)\n");
printf("Please select 1,2,3,4: \n");
scanf("%d",&choice);
if(choice == 1)
printf("Number of citizen(resident) is %d.\n",year2013[0]);
else if(choice == 2)
printf("Number of PR(resident) in thousands is %d.\n",year2013[1]);
else if(choice == 3)
printf("Number of non-resident in thousands is %d.\n",year2013[2]);
else if(choice == 4)
printf("Land area(sq.km.) is %d.\n",year2013[3]);
else
printf("You have select a wrong choice.\n");
break;
case'5':
printf("1-Number of citizen in thousands\n");
printf("2-Number of PR(resident) in thousands\n");
printf("3-Number of non-resident in thousands\n");
printf("4-Land area(sq.km.)\n");
printf("Please select 1,2,3,4: \n");
scanf("%d",&choice);
if(choice == 1)
printf("Number of citizen(resident) is %d.\n",year2014[0]);
else if(choice == 2)
printf("Number of PR(resident) in thousands is %d.\n",year2014[1]);
else if(choice == 3)
printf("Number of non-resident in thousands is %d.\n",year2014[2]);
else if(choice == 4)
printf("Land area(sq.km.) is %d.\n",year2014[3]);
else
printf("You have select a wrong choice.\n");
break;
default:printf("You have selected a wrong choice\n");
}//switch
}// main
The previous problem managed to go away but now whenever i select a option this happened.
MENU
-----
1-Population of 2010
2-Population of 2011
3-Population of 2012
4-Population of 2013
5-Population of 2014
Please select 1,2,3,4 or 5:1
MENU
-----
1-Population of 2010
2-Population of 2011
3-Population of 2012
4-Population of 2013
5-Population of 2014
Please select 1,2,3,4 or 5:2
MENU
-----
1-Population of 2010
2-Population of 2011
3-Population of 2012
4-Population of 2013
5-Population of 2014
Please select 1,2,3,4 or 5:3
MENU