You've Got To Please The Compiler :)
If you try to run (compile) your code as a C++ code, you'll get the following error in the Online GDB Compiler:
main.cpp:50:14: error: jump to case label [-fpermissive]
This is a bit cryptic, but what it really means is that your variables defined in one case are visible in another case. This is normally a warning, but it looks like it's been turned into an error in the compiler settings.
Normally you can just search the flag (fpermissive) to find out what it is for. You'll find plenty of explanations, just like this.
Now, that we know what the problem is, we need to solve it. One of the easiest solutions is to have every case in your switch its own scope.
switch (h1)
{
case 1:
{
// Your code comes here...
}
break;
case 2:
{
// Your code comes here...
}
break;
case 3:
{
// Your code comes here...
}
break;
default:
{
// Your code comes here...
}
break;
}
It is also a good idea to double-check whether all of your cases (including default) are closed with a break statement. This prevents the execution of code to jump from one case to another.
After this fix, your code compiles and runs.
Incorrect Behaviour
Your solution for "Assignment3 - Even or Odd Number" is wrong. The program suggests you'll tell if the number entered is even or odd, but apparently, you do not know what even and odd numbers are.
Even numbers can be divided by 2 without any remainder. Such as 0, 2, 4, 6, etc (negative numbers work just fine too).
Odd numbers can not be divided by 2 without any reminder. Such numbers are 1, 3, 5, 7, etc (negative numbers work here too).
What your code does is this:
if(n > 10 || n < 30){
cout<<n<<" is an odd number"<<endl;
}
You have already sanitized your input and at this point, n could be only in the range [10, 30].
But even without this your expression (n > 10 || n < 30) always evaluates to true as a number really is always larger than 10, or less than 30, because if it would be smaller or equal to ten, it would be still less than 30.
And as explained above, being even or odd depends on whether a number can be divided by 2 with/out any reminder.
I'd suggest fixing this.
Funny Way To Say Always
In your "Quiz4 - Box Pattern" you wrote the following code:
for(int rows=0;rows!=n1;rows++){
for(int cols=0;cols!=n2;cols++){
if(rows==0 || rows==n1 || cols==0 || cols==n2){
cout<<"*"<<"\t";
}else cout<<"*"<<"\t";
}
cout<<endl;
}
Your code above really is equivalent to
for (int rows = 0; rows != n1; rows++)
{
for (int cols = 0; cols != n2; cols++)
cout << "*\t";
cout<<endl;
}
, as your if's true and false branch does exactly the same thing. So why complicate things? :)