小编use*_*043的帖子

我的do-while循环没有结束

我是c ++的新手,很抱歉,如果这个问题非常简单.我正在用c ++编写一个程序来掷骰子并显示它的数字,直到用户键入单词cancel但我的循环没有结束,即使我输入取消我的代码(我用的是dev c ++):

#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int dice (int);
int main()
{
    char k[7];
    int x;
    do
    {
          cout<<"your dice number is: "<<dice(x)<<endl;
          cout<<"do you want to cancel or continue?";
          cin>>k;
     }while(k!="cancel");
          cout<<"END";
          getch();
}
int dice (int a)
{   
    srand(time(NULL));
    for(int i=1;i<100;i++)
        {
            a=(rand()% 6)+1;
        }
            return a;        
}
Run Code Online (Sandbox Code Playgroud)

c++ do-while

4
推荐指数
1
解决办法
329
查看次数

如何在4个字符串之间搜索字符串

我想编写一个程序,从用户那里获取大约4个字符串,然后要求用户键入一个字符串,以查看该字符串是否存在于已输入的4个字符串之一中.请您纠正我的错误.谢谢. (我用dev c ++)

#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int main()
{   
    int x,y,i;
    string z[40],a;
    for (int i=0;i<4;i++)
    {
        cout<<"type 4 strings";
        cin>>z[i];
     }
        cout<<"type a string to search ";
        cin>>a;
    for (int i=0;i<4;i++)
    {   if(strcmp(z[i],a)==0)
        cout<<z[i];
        else
        cout<<"error";
    }
    getch ();   
    return 0;   
}
Run Code Online (Sandbox Code Playgroud)

c++ string

0
推荐指数
1
解决办法
71
查看次数

标签 统计

c++ ×2

do-while ×1

string ×1