在编译此语句时,switch语句在case 8和case 9中出错
srand(time(0));
int random = (rand() %10) + 1;
LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV", "random number for BVS [%d]",random);
switch (random)
{
case 1:
LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV", "Right Hand Thumb");
random = 01;
break;
case 2:
LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV", "Right Hand Index Finger");
random = 02;
break;
case 3:
LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV", "Right Hand Middle Finger");
random = 03;
break;
case 4:
LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV", "Right Ring Finger");
random = 04;
break;
case 5:
LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV", "Right Hand Baby Finger");
random = 05;
break;
case 6:
LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV", "Left Hand Thumb");
random = 06;
break;
case 7:
LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV", "Left Hand Index Finger");
random = 07;
break;
case 8:
LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV", "Left Hand Middle Finger");
random = 08;
break;
case 9:
LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV", "Left Ring Finger");
random = 09;
break;
case 10:
LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV", "Left Hand Baby Finger");
random = 10;
break;
default:
LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV", "Random Number not generated successfully");
break;
}
Screenshot
编译代码时遇到此错误
1条答案
按热度按时间tvz2xvvm1#
从数字
0
开始的整数文字是以8为基数的八进制整数文字。从C++语法
和
所以这些记录
和
无效。如您所见,对于基数
8
,有效数字包括0 -7
。写就行了
和
使用十进制整数文字
8
和9
。为了避免代码的读者感到困惑,请删除整数文字中的所有前导零。
另外,为常量引入一个有作用域或无作用域的枚举,并在case标签和赋值语句中使用它们也是一个好主意。