请问C++里面可以随机出一个符号吗?

来源:百度知道 编辑:UC知道 时间:2024/06/04 23:28:26
我想把加减乘除号进行随机输出,并进行运算,请问可以随机出来吗?
要怎么用?
不胜感谢!

#include<iostream>
#include<ctime>
#include<cstring>
using namespace std;
void main()
{
char ch='/';//+ - * / 43,45,42,47
int temp1,temp2,answer;
cout<<"input your answer,quit by -1"<<endl;
srand((unsigned int)time(NULL));
do{
int temp=rand()%8;
if(temp==2||temp==3||temp==5||temp==7)
{
temp1=rand()%10;
temp2=rand()%10;
cout<<temp1<<char(temp+40)<<temp2<<"=";
cin>>answer;
if(answer==-1)break;
else{
switch(char(temp+40))
{
case '+':if(answer==(temp1+temp2))cout<<"right,next title:"<<endl;else cout<<"wrong!"<<endl;break;
case '-':if(answer==(temp1-temp2))cout<<"right,next title:"<<endl;else cout<<"wrong!"<<endl;break;