can someone please help; its telling me that case 2 not within a switch case?
how do i keep count of the code the user selected
for example how many students calculated under case 1
#include<iostream.h>
#include<conio.h>
main()
{
char name[25];
int code;
int credits;
int tuition,sum=0;
int student_count=0;
int PT_count=0;
int FT_count=0;
cout<<"Enter Student Name"<<endl;
cin>>name;
cout<<"Enter 1 if student is a resident or\n[ Enter 2 if a student is not a resident"<<endl;
cin>>code;
while (code!=0)
{
switch(code)
case 1:
cout<<"Enter the credit amount"<<endl;
cin>>credits;
if(credits>=12)
tuition=600;
else
tuition=credits*50;
break;
case 2:
cout<<"Enter the credit amount"<<endl;
cin>>credits;
if (credits>=12)
tuition=1320;
else
tuition=credits*110;
break;
default:
cout<<"Invalid Code"<<endl;
Well first of all, you have a problem with the employees name. You're trying to put the whole name into a single char variable, but a char variable can only hold one letter. You can fix this by using a char array rather than just a single char. All you have to change is instead of
While you don't HAVE to do it this way, the way you're doing it could cause some problems. For instance, you're passing tax to the calc_tax function before you assign any value to tax, which could cause some problems (it did with my compiler).
Omitting the braces that surround the cases of a switch statement will mean that the switch can only handle a single case. Add braces around the case statements and you're good to go.