English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Is this the appropiate way to using the switch structure im having problems, sending it to an outfile char User_input;
switch (User_Input)
{
case 'short'
outfile << setw(6) << Band_Name << setw(6)<< Title << endl;
break;

case 'medium'
outfile << setw(6) << Band_Name << setw(6)<< Title << setw(6) << number_Of_Tracks << endl;
break;

case 'long'
outfile << setw(6)<< Band_Name << setw(6) << Title << setw(6) << number_Of_Tracks << setw(6)<< Total_Time
<< setw(6)<< Cost << endl;
break;
}
system ("Pause");
return Exit_SUCESS;
}

2007-03-11 15:31:43 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

Thanks you guys rock! :)

2007-03-11 16:03:36 · update #1

4 answers

you are missing the colons. None of those statements are being evaluated. it should be case 'short': and so on. The colon after the case is important.

2007-03-11 15:37:18 · answer #1 · answered by michael p 4 · 0 0

Yes and no. This is an okay way to do it, but there is a better way to do it to simplify the code. Since you have some duplicated code, you can simply do the following.

Is this the appropiate way to using the switch structure im having problems, sending it to an outfile char User_input;
outfile << setw(6) << Band_Name << setw(6)<< Title;
switch (User_Input)
{
case "short"
break;
case "medium":
outfile << setw(6) << number_Of_Tracks;
break;
case "long":
outfile << setw(6) << number_Of_Tracks << setw(6)<< Total_Time << setw(6)<< Cost;
break;
}
outfile << endl;
system ("Pause");
return Exit_SUCESS;
}

Also, notice that your strings need double quotes, not single quotes, as those a characters, and you needed the colons too.

2007-03-11 22:48:13 · answer #2 · answered by Anonymous · 0 0

First, you cannot use single quotes with strings.
Second, in C++ switch() you cannot use strings. Use integer values.
Third, every case has to have colon at the end.
switch (User_Input[0])
{
case 's': // instead of "short"
...
case 'm': // instead of "medium"
...
}
will work

2007-03-11 23:31:43 · answer #3 · answered by alakit013 5 · 0 0

You need a colon at the end of the case statements.

2007-03-11 22:37:43 · answer #4 · answered by generic 2 · 0 0

fedest.com, questions and answers