如何将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) 题:
反复滚动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相同,程序也不会停止.
我一直试图让这个程序正常工作.它确实编译,但它没有提示用户输入,而是说明了一些不正确的内容.
提示:
询问用户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)