我的问题是如何将struct.variable(或结构数组)传递给void函数.基本上代码如下:
结构
struct Person{
string surname;
string BType;
string organ;
int age;
int year, ID, IDp;
} Patient[50], Donor[50];
int i; // counter variables for the arrays such as Patient[i].BType... etc
int i1;
Run Code Online (Sandbox Code Playgroud)
那么函数的代码是这样的一行:
void compare(int &i, int &i1, Person &Patient[50], Person &Donor[50]);
Run Code Online (Sandbox Code Playgroud)
我试图通过i,i1,Patient和Donor结构.为什么这不起作用?有没有一种特殊的方法将这些结构传递给函数?
变量结构中的值也是从文件中读取的(不要认为这会改变任何内容).有任何想法吗?
题:
反复滚动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相同,程序也不会停止.
我正在实施这个:
double x;
ostringstream x_convert;
x_convert << x;
string x_str = x_convert.str();
Run Code Online (Sandbox Code Playgroud)
这看起来有点多余.有更优雅的方式吗?
我试图DatePickerDialog在明年展示,但我得到1900.这段代码有什么问题?
.get(Calendar.YEAR + 1),
Run Code Online (Sandbox Code Playgroud)