would really appriciate someone clarifying a couple of questions for me..
first question:
I typed this code in
and got the errorCode:#include<iostream> using namespace std; char input[101]; class a_class { char* first; char* second; public: a_class(){ cout << "What is your first input ?\n"; cin.getline(input, 100); this->first = new char[strlen(input) + 1]; strcpy(this->first, input); cout << "What is your second input ? "; cin.getline(input, 100); this->second = new char[strlen(input) + 1]; strcpy(this->second, input); } ~a_class(){}; }; void main(){ int slct; do{ cin >> slct; switch ( slct ) { case 0 : break; case 1 : cout << "You picked 1" << endl; a_class a; break; case 2 : break; default : break; } }while (slct != 5); }
i found out that to solve this error i had to put brackets aroundCode:initialization of 'a' is skipped by 'case' label
can someone plz clarify to me in simple terms, why the brackets are needed.Code:{ cout << "You picked 1" << endl; a_class a; break; }
Second:
After adding the brackets and inputing "1" as the switch, I get the following.
the problem with this is that i wasn't able to input my "first input" in the first place.. it just skipped the 'cin' and went to the next one..Code:You picked 1 What is your first input ? What is your second input?
Please explain why this is happening and how i can fix it.
Replies are greatly appriciated!!!!!


