回复 3楼 ToBeOOP
#include <iostream>
#include <cmath>
#include <iomanip>
#include <stdlib.h>
using namespace std;
int menu(void);
void input(void);
void output(void);
void mean(void);
void tvalue(void);
double a[3][3];
double b[3][3];
double meana;
double meanb;
int q;
int s;
int main()
{
int Num;
while((Num=menu())!=5)
{
switch(Num)
{
case 1:
input();
break;
case 2:
output();
break;
case 3:
mean();
break;
case 4:
tvalue();
break;
default:
cout<<"select Number 1 to 5 please"<<endl;
break;
}
}
cout<<"Thanks for using the paired t-test program"<<endl;
return 0;
}
int menu(void)
{
int N;
cout<<endl;
cout<<"1.Input scores"<<endl;
cout<<"2.Show scores "<<endl;
cout<<"3.Calculate and display mean values"<<endl;
cout<<"4.Calculate and display t-value and alpha_level"<<endl;
cout<<"5.Exit"<<endl;
cin>>N;
return N;
}
void input(void)
{
cout<<"Please enter nine scores before the training session."<<endl;
double m;
for(int i=0;i<3;i++)
for(int j=0;j<3;)
{
cin>>m;
if(m>0&&m<20)
{a[i][j]=m;
j++;
}
else
cout<<"The Number"<<m<<" out of range,should be 0 to 20,Please enter again."<<endl;
}
cout<<"Nine scores before the training session successfully entered."<<endl;
cout<<"Please enter Nine scores After the training session ."<<endl;
for(int i=0;i<3;i++)
for(int j=0;j<3;)
{
cin>>m;
if(m>=0&&m<=20)
{b[i][j]=m;
j++;
}
else
cout<<"The Number "<<m<<" out of range,should be 0 to 20,Please enter again."<<endl;
}
cout<<"Nine scores After the training session successfully entered."<<endl;
system("pause");
}
void output(void)
{
q=0;
cout<<"pair"<<"
"<<"Before Tr."<<"
"<<"After Tr."<<endl;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
{
q++;
cout<<setiosflags(ios::fixed)<<setprecision(1)<<"
"<<q<<"
"<<a[i][j];
if(a[i][j]<15)
if(a[i][j]<10)
cout<<"**";
else
cout<<"*";
cout<<setiosflags(ios::fixed)<<setprecision(1)<<"
"<<b[i][j];
if(b[i][j]<15)
if(b[i][j]<10)
cout<<"**";
else
cout<<"*";
cout<<endl;
}
system("pause");
}
void mean(void)
{
double suma;
double sumb;
suma=0;
sumb=0;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
{
suma=suma+a[i][j];
sumb=sumb+b[i][j];
}
meana=suma/q;
meanb=sumb/q;
cout<<"mean(before)="<<meana<<endl;
cout<<"mean(after)="<<meanb<<endl;
system("pause");
}
void tvalue(void)
{
double summ;
double tvalue;
double alpha;
summ=0;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
summ=summ+ pow(abs(a[i][j]-meana)-abs(b[i][j]-meanb),2);
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
tvalue=abs(meana-meanb)* sqrt((q*(q-1))/summ);
cout<<"T-value="<<tvalue<<endl;
if(tvalue<=1.9600)
if(tvalue<=1.6450)
if(tvalue<=1.2820)
alpha=0.100;
else
alpha=0.05;
else
alpha=0.025;
else
alpha=0.001;
cout<<"Alpha_level"<<(tvalue)<<"="<<alpha<<endl;
system("pause");
}
这个是我的全部代码
当我用空格的时候
虽然提示超出范围 但是当我重新输入的时候 顺序就乱了
比如说我输入 1.2.3.4.56.78.9.0.14
然后会提示 56 和78 超出范围, 当我重新输入的时候顺序就打乱了
比如我重新输入 17 和18
顺序就会变成1.2.3.4.9.0.14.17.18
而不是我我想要的1.2.3.4.17.18.9.0.14。 我用 回车输入的话就没有这个问题
,
有什么办法能解决么 ?