小编use*_*477的帖子

将ascii值转换为char

如何将5个随机ascii值转换为chars?


提示:

从97到122随机生成5个ascii值(所有字母表的ascii值).当你去的时候,确定与每个ascii值对应的字母,并输出由5个字母组成的单词.

我的代码:

#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main ()
{
srand (time(NULL));
int val1= rand()%122+97;
int val2= rand()%122+97;
int val3= rand()%122+97;
int val4= rand()%122+97;
int val5= rand()%122+97

cout<<val1<<" and "<<val2<<" and "<<val3<<" and "<<val4<<" and "<<val15<<". "<<






return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ ascii

6
推荐指数
2
解决办法
9万
查看次数

C++骰子程序困难

题:

反复滚动3个骰子,直到双打滚动(任何两个是相同的).每次显示值,然后显示获得双打所需的尝试次数.

我的代码:

#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main ()
{
    srand (time(NULL));
    int j=1;
    int i=0;
    int a;
    int b;

    do
    {
        int a=(rand ()%6+1);
        int b=(rand ()%6+1);

        cout<<a<<" and "<<b<<endl<<endl;
        j++;
    }
    while (a!=b);

    cout<<"They are the same!"<<endl<<endl;
    cout<<"It took "<<j<<" tries.";

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

问题:

循环不会停止.即使a和b相同,程序也不会停止.

c++ random loops

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

For Loop无法正常工作(c ++)

我一直试图让这个程序正常工作.它确实编译,但它没有提示用户输入,而是说明了一些不正确的内容.

提示:

询问用户10个课程标记(从0到100)以及之后的状态(在标签中)有多少通过标记.

我的代码:

#include <iostream>
#include <time.h>
#include <stdlib.h>

using namespace std;

int main()
{
    int mark;
    int passinggrades = 0;
    for(int i = 0; i > 10; i++)
    {
        cout << "Enter Mark:";
        cin >> mark;
        while(mark >= 50)
        {
            passinggrades++;
        }
    }
    cout << j << " of your marks were passing grades.";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ loops for-loop

-2
推荐指数
1
解决办法
2597
查看次数

标签 统计

c++ ×3

loops ×2

ascii ×1

for-loop ×1

random ×1