Teen Programmers Unite  
 

 

Return to forum top

can (switch) be a part of a loop???

Posted by matheo917 [send private reply] at September 20, 2001, 07:03:38 PM

i'm using a switch statment inside of a loop
for some reason first switch case executes but when the loop starts over seams like the other cases aren't even touched
here's an example:


const int MaxMonths = 12;

for(int k = 0; k < MaxMonths; ++k) // Iterates 12 times


switch (k)
{
case 0: {cout << "Janurary "; break;}
case 1: {cout << "Febrary "; break;}
case 2: {cout << "March "; break;}
case 3: {cout << "April "; break;}
case 4: {cout << "May "; break;}
case 5: {cout << "June "; break;}
case 6: {cout << "July "; break;}
case 7: {cout << "August "; break;}
case 8: {cout << "September "; break;}
case 9: {cout << "Octoter "; break;}
case 10: {cout << "November "; break;}
case 11: {cout << "December "; break;}
}

}



first line prints January and then no other (months) are printed..

hmmmm...
what you guys think???

Posted by CHollman82 [send private reply] at September 20, 2001, 07:18:55 PM

#include <iostream.h>
#include <conio.h>

void main()
{
const int MaxMonths = 12;

for(int k = 0; k < MaxMonths; ++k) // Iterates 12 times
{
switch (k)
{
case 0: {cout << "Janurary "; break;}
case 1: {cout << "Febrary "; break;}
case 2: {cout << "March "; break;}
case 3: {cout << "April "; break;}
case 4: {cout << "May "; break;}
case 5: {cout << "June "; break;}
case 6: {cout << "July "; break;}
case 7: {cout << "August "; break;}
case 8: {cout << "September "; break;}
case 9: {cout << "Octoter "; break;}
case 10: {cout << "November "; break;}
case 11: {cout << "December "; break;}
}
}
getch();
}


I compiled and executed this exact code in borland and it worked perfectly.

Posted by matheo917 [send private reply] at September 20, 2001, 07:25:22 PM

i found the mistake already, the problem was somewhere else

apreciate the effort...

Regards,
matheo917

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.