0
#include<stdio.h>
# include<stdlib.h>

struct manager {
char name[10];
int age;
int salary;
}biocon,panacea,serum;
manager *p;
int opt;
int main() {
	printf("DATABASE FOR BIOCON manager\n");
	printf("Please enter name: \n");
	scanf("%c",biocon.name);
	printf("Please enter age: \n");
	scanf("%d",&biocon.age);
	printf("Please enter salary: \n");
	scanf("%d",&biocon.salary);

	printf("DATABASE FOR PANACEA manager\n");
	printf("Please enter name: \n");
	scanf("%c",panacea.name);
	printf("Please enter age: \n");
	scanf("%d",&panacea.age);
	printf("Please enter salary: \n");
	scanf("%d",&panacea.salary);

	printf("DATABASE FOR SERUMBIOTEK manger\n");
	printf("Please enter name: \n");
	scanf("%c",serum.name);
	printf("Please enter age: \n");
	scanf("%d",&serum.age);
	printf("Please enter salary: \n");
	scanf("%d",&serum.salary);
	printf("please follow option 1:biocon,2:panacea,3:serum");
	scanf("%d",&opt);
	switch(opt) {
		case 1:
		manager *p=&biocon;
		break;
		case 2:
		manager *p=&panacea;
		break;
		case 3:
		manager *p=&serum;
		break;
		default:
		printf("please see menu\n");
		exit(1);
	}
	printf("the pay of %c is %d Rs whose age is %d years",p->name,p->salary,p->age);
 return 0;
}

in above code i m trying to use concepts of structure, pointers to a structure etc.while compiling i get following errors..

g++ -o pntrfunc /exploitation_studies/c++/pntrfunc.cpp
/exploitation_studies/c++/pntrfunc.cpp: In function ‘int main()’:
/exploitation_studies/c++/pntrfunc.cpp:41: error: jump to case label
/exploitation_studies/c++/pntrfunc.cpp:39: error: crosses initialization of ‘manager* p’
/exploitation_studies/c++/pntrfunc.cpp:42: error: redeclaration of ‘manager* p’
/exploitation_studies/c++/pntrfunc.cpp:39: error: ‘manager* p’ previously declared here
/exploitation_studies/c++/pntrfunc.cpp:44: error: jump to case label
/exploitation_studies/c++/pntrfunc.cpp:39: error: crosses initialization of ‘manager* p’
/exploitation_studies/c++/pntrfunc.cpp:45: error: redeclaration of ‘manager* p’
/exploitation_studies/c++/pntrfunc.cpp:39: error: ‘manager* p’ previously declared here
/exploitation_studies/c++/pntrfunc.cpp:47: error: jump to case label
/exploitation_studies/c++/pntrfunc.cpp:39: error: crosses initialization of ‘manager* p’
/exploitation_studies/c++/pntrfunc.cpp:51: warning: format ‘%c’ expects type ‘int’, but argument 2 has type ‘char*’

can some1 please explain where and why i am wrong and how to fix??

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

First off, that is a C program, not a C++ program.

To fix the errors, declare manager* outside the switch statement. It does no good to declare the pointers like you did because they do nothing and are destroyed as soon as the break statement is executed.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.