如何创建一个从 1 -> 生成十个随机数的程序RAND_MAX?
RAND_MAX必须是用户输入的数字。
#include <iostream>
#include <stdlib.h>
int main()
{
using namespace std;
int x;
int y;
Random:
{
x = rand();
cout << x << endl;
}
y = y + 1;
if (y == 10) {
return 0;
}
goto Random;
}
Run Code Online (Sandbox Code Playgroud) 一位优秀的绅士告诉我,goto语句不好,但我不知道我怎么不能在这里使用它:
int main()
{
using namespace std;
int x;
int y;
int z;
int a;
int b;
Calc: //How can i get back here, without using goto?
{
cout << "To begin, type a number" << endl;
cin >> x;
cout << "Excellent!" << endl;
cout << "Now you need to type the second number" << endl;
cin >> y;
cout << "Excellent!" << endl;
cout << "Now, what do you want to do with these numbers?" << endl;
cout …Run Code Online (Sandbox Code Playgroud) 我做了一个调用这个函数的程序.我知道这是因为"Int Strength已被调用"出现在输出框中.但是,它不会改变我告诉它要做的值.我希望它从main()获取整数值,然后使用它们并返回新值.我使用的头文件只包含"int strength(int a,int s,int i)"
int strength(int a, int s, int i)
{
using namespace std;
cout << "Int Strength has been called" << endl;
a = a + i;
s = s - i;
return a;
return s;
}
Run Code Online (Sandbox Code Playgroud)