C++ 在C+中使用sqrt时出错+;

C++ 在C+中使用sqrt时出错+;,c++,statistics,calculator,C++,Statistics,Calculator,我正在为我的统计类编写一个计算器,但我的代码有问题。这用于计算置信区间。当我使用sqrt时,我得到了“多个重载函数实例错误”。还有一些我无法确定的其他问题。我正在使用VisualStudio2010和win32控制台应用程序。如果你能帮我的话,那会很有帮助的。(我不熟悉编码,所以请忍受我糟糕的编码。) #包括“stdafx.h” #包括 #包括 #包括 #杂注警告(禁用:4996) int _tmain(int argc,_TCHAR*argv[] { 双样本=0,z=0,样本1=0; 双标准=

我正在为我的统计类编写一个计算器,但我的代码有问题。这用于计算置信区间。当我使用
sqrt
时,我得到了“多个重载函数实例错误”。还有一些我无法确定的其他问题。我正在使用VisualStudio2010和win32控制台应用程序。如果你能帮我的话,那会很有帮助的。(我不熟悉编码,所以请忍受我糟糕的编码。)

#包括“stdafx.h”
#包括
#包括
#包括
#杂注警告(禁用:4996)
int _tmain(int argc,_TCHAR*argv[]
{
双样本=0,z=0,样本1=0;
双标准=0,误差=0,采样根=0,误差1=0;
printf(“Z分数是多少?”);
scanf(“%d\n”、&z);
printf(“什么是std?”);
scanf(“%lf\n”、&std);
printf(“样本量是多少?”);
scanf(“%d\n”,&sample);
printf(“错误是什么?”);
扫描频率(“%lf”,错误(&R);
//sampleroot=sqrt(样本);
误差1=z*(标准/标准偏差((双)样本));
样本1=((z*std)/错误)*((z*std)/错误);
printf(“错误=%lf\n”,错误1);
printf(“样本为%d\n”,样本1);
系统(“暂停”);
返回0;
}

那是我的新密码。当我运行它时,它只询问前3个printfs并直接跳到解决方案。如何解决此问题。

C++中有三个sqrt函数:

double sqrt(double _X);
float sqrt(float _X);
long double sqrt(long double _X);
您将
sample
声明为int(可以转换为float或double),因此编译器不知道调用哪个函数

您可以选择您想要的并进行类型转换,
sqrt((double)sample)
,或者您可能只想首先将sample声明为double。事实上,您可能希望所有的
int
s都是
double
s

编辑
scanf(“%lf”、&error)中的
错误之前需要一个
另外,我认为您需要从
scanf()
格式中删除所有
\n

C++中有三个sqrt函数:

double sqrt(double _X);
float sqrt(float _X);
long double sqrt(long double _X);
您将
sample
声明为int(可以转换为float或double),因此编译器不知道调用哪个函数

您可以选择您想要的并进行类型转换,
sqrt((double)sample)
,或者您可能只想首先将sample声明为double。事实上,您可能希望所有的
int
s都是
double
s

编辑
scanf(“%lf”、&error)中的
错误之前需要一个
另外,我认为您需要从
scanf()
格式中删除所有
\n

谢谢大家的帮助。如果有人想用它来查找置信区间内的错误和样本大小,下面是工作代码

#include "stdafx.h"
#include <cstdlib>
#include <stdio.h>
#include <math.h>
#pragma warning(disable: 4996)

int _tmain(int argc, _TCHAR* argv[])
{
double sample = 0, z = 0, sample1 = 0;
double std = 0, error = 0, sampleroot = 0, error1 = 0;

printf("What is the Z score?");
scanf("%lf", &z);

printf("What is the std?");
scanf("%lf", &std);

printf("What is the sample size?");
scanf("%lf", &sample);

printf("What is the Error?");
scanf("%lf", &error);

//sampleroot = sqrt(sample);
error1 = z * (std/sqrt((double)sample));
sample1 = ((z * std) / error) * ((z * std) / error);

printf("Error = %lf\n", error1);
printf("Sample is %d\n", sample1);


system("pause");
return 0;
}
#包括“stdafx.h”
#包括
#包括
#包括
#杂注警告(禁用:4996)
int _tmain(int argc,_TCHAR*argv[]
{
双样本=0,z=0,样本1=0;
双标准=0,误差=0,采样根=0,误差1=0;
printf(“Z分数是多少?”);
扫描频率(“%lf”、&z);
printf(“什么是std?”);
扫描频率(“%lf”和标准);
printf(“样本量是多少?”);
扫描频率(“%lf”和样本);
printf(“错误是什么?”);
扫描频率(“%lf”,错误(&R);
//sampleroot=sqrt(样本);
误差1=z*(标准/标准偏差((双)样本));
样本1=((z*std)/错误)*((z*std)/错误);
printf(“错误=%lf\n”,错误1);
printf(“样本为%d\n”,样本1);
系统(“暂停”);
返回0;
}

谢谢大家对我的帮助。如果有人想用它来查找置信区间内的错误和样本大小,下面是工作代码

#include "stdafx.h"
#include <cstdlib>
#include <stdio.h>
#include <math.h>
#pragma warning(disable: 4996)

int _tmain(int argc, _TCHAR* argv[])
{
double sample = 0, z = 0, sample1 = 0;
double std = 0, error = 0, sampleroot = 0, error1 = 0;

printf("What is the Z score?");
scanf("%lf", &z);

printf("What is the std?");
scanf("%lf", &std);

printf("What is the sample size?");
scanf("%lf", &sample);

printf("What is the Error?");
scanf("%lf", &error);

//sampleroot = sqrt(sample);
error1 = z * (std/sqrt((double)sample));
sample1 = ((z * std) / error) * ((z * std) / error);

printf("Error = %lf\n", error1);
printf("Sample is %d\n", sample1);


system("pause");
return 0;
}
#包括“stdafx.h”
#包括
#包括
#包括
#杂注警告(禁用:4996)
int _tmain(int argc,_TCHAR*argv[]
{
双样本=0,z=0,样本1=0;
双标准=0,误差=0,采样根=0,误差1=0;
printf(“Z分数是多少?”);
扫描频率(“%lf”、&z);
printf(“什么是std?”);
扫描频率(“%lf”和标准);
printf(“样本量是多少?”);
扫描频率(“%lf”和样本);
printf(“错误是什么?”);
扫描频率(“%lf”,错误(&R);
//sampleroot=sqrt(样本);
误差1=z*(标准/标准偏差((双)样本));
样本1=((z*std)/错误)*((z*std)/错误);
printf(“错误=%lf\n”,错误1);
printf(“样本为%d\n”,样本1);
系统(“暂停”);
返回0;
}

我插入了sqrt((双精度)示例),但仍然在Stats.exe中的0x0f9700d8(msvcr100d.dll)处获得未处理的异常:0xc00005:访问冲突写入位置0x00000000。在此语句
scanf(“%lf”,&error)中需要
。我插入了sqrt((双精度)示例),但仍然在Stats.exe中的0x0f9700d8(msvcr100d.dll)处获得未处理的异常:0xC0000005:访问冲突写入位置0x00000000。在此语句中需要
 >注意<代码> <代码>是纯C++头,不能在C程序中使用。重载也是C++中的问题,而不是C中的问题;C中没有重载函数。因此,您不在C中工作——如果C++编译时C++编译器使用C++编译器,而不是在C模式下,如果编译时编译成任何地方。<代码> SCANF(“%D\N”,Z);代码>删除
\n
-->
scanf(“%d”和&z)注意<代码> <代码>是纯C++标题,不能在C程序中使用。重载也是C++中的问题,而不是C中的问题;C中没有重载函数。因此,您不在C中工作——如果C++编译时C++编译器使用C++编译器,而不是在C模式下,如果编译时编译成任何地方。<代码> SCANF(“%D\N”,Z);代码>删除
\n
-->
scanf(“%d”和&z)