c++ 一个程序不能运行

来源:百度知道 编辑:UC知道 时间:2024/05/31 00:23:37
#include <iostream>
#include <cstdlib>
#include<ctime>
using namespace std;
void main()
{
int count(0),count2(0),count3(0),count4(0),count5(0);
srand((unsigned)time(NULL));
int color=rand()%6;
while(color)
{
switch(color)
{
case 1:
cout<<"红球"<<endl;
count1++;
break;
case 2:
cout<<"黄球"<<endl;
count2++;
break;
case 3:
cout<<"蓝球"<<endl;
count3++;
break;
case 4:
cout<<"绿球"<<endl;
count4++;
break;
case 5:
cout<<"白球"<<endl;
count5++;
break;
default:
cout<<"不正确"<<endl;
}
color=rand()%6;
}
cout<<"每种球的次数(红,黄,蓝,绿,白):"
<<count1<<","<<count2<<","<

#include <iostream>
#include <cstdlib>
#include<ctime>
using namespace std;
int main() //////////////// change from void to int
{
int count1(0),count2(0),count3(0),count4(0),count5(0);
/////////////////// change from count to count1
srand((unsigned)time(NULL));
int color=rand()%6;
while(color)
{
switch(color)
{
case 1:
cout<<"红球"<<endl;
count1++; // 没有声明!
break;
case 2:
cout<<"黄球"<<endl;
count2++;
break;
case 3:
cout<<"蓝球"<<endl;
count3++;
break;
case 4:
cout<<"绿球"<<endl;
count4++;
break;
case 5:
cout<<"白球"<<endl;
count5++;
break;
default:
cout<<"不正确"<<endl;
}
color=rand()%6;
}
cout<<"每种球