| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 869 人关注过本帖
标题:新手求解!~~~ 请各位大侠进来看下 回车 和空格的区别 ?
只看楼主 加入收藏
wanxinbo
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-1-5
结帖率:0
收藏
已结贴  问题点数:20 回复次数:8 
新手求解!~~~ 请各位大侠进来看下 回车 和空格的区别 ?
我刚刚写的程序

cout<<"Please enter nine scores before the training session."<<endl;
        double m;
        double a[3][3];
        double b[3][3];
        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 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;j++)
                {   cin>>m;
                    b[i][j]=m;
        }
        cout<<"Nine scores After the training session successfully entered."<<endl;


这个就是说要给 数列赋值  但是当我用回车赋值的时候 一切ok  但是用 空格赋值的时候 就出现问题了  如说  我赋值 1.2.3.4.5.6。到9
9 个数字  没打一个数我打一次 回车 就是赋值9次   这个没问题  但是当我 每打一个数字打一次 空格  问题就出现了
因为我这个程序只能输入 0-20的数字  如果超出了  就会有提示  我安空格的时候是没有提示的。 能不能 我按空格的时候 就像我用回车的时候一样  按完马上就会有提示说 超出范围 ?
搜索更多相关主题的帖子: before double training scores should 
2012-01-05 17:14
wanxinbo
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-1-5
收藏
得分:0 
2012-01-05 17:23
ToBeOOP
Rank: 3Rank: 3
等 级:论坛游侠
威 望:3
帖 子:106
专家分:181
注 册:2010-7-8
收藏
得分:10 
我试过了你所说的两种输入方式..但是都会提示超出范围...我的用的是Win7和Visual studio 2010
2012-01-05 20:10
wanxinbo
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-1-5
收藏
得分:0 
回复 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。 我用 回车输入的话就没有这个问题     有什么办法能解决么 ?
2012-01-06 15:26
ToBeOOP
Rank: 3Rank: 3
等 级:论坛游侠
威 望:3
帖 子:106
专家分:181
注 册:2010-7-8
收藏
得分:0 
问题在于输入时候的问题..程序本身是没问题的..   
            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;
         }
举个例子:在这里如果输入1 2 3 4 5 6 7 8 9 21就会被提示重新输入..这时只需要输入一个被允许的就可以了..不需要将前面的数都重新输入..因为J的值并不是0了..而是经过自增的!
2012-01-06 19:22
lucky563591
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:765
专家分:2103
注 册:2009-11-18
收藏
得分:10 
要设置状态位的,很麻烦,不如按行读取。
2012-01-07 10:14
wanxinbo
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-1-5
收藏
得分:0 
回复 5楼 ToBeOOP
我不是说全部重新输入  但是我还是想要原来的顺序 如果输入的是1.2.3.4.21.6.7.8.9
会要求重新输入一个数 然后输入 5
这个时候 你回到目录菜单的的时候按2   会发现 不是想要的 1.2.3.4.5.6.7.8.9  而是 1.2.3.4.6.7.8.9.5
2012-01-07 15:38
wanxinbo
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-1-5
收藏
得分:0 
回复 6楼 lucky563591
你说的 按行读取是什么? 不太明白  能请教下么? 大概说下  我去网上查, 还有 要设置什么状态 ?
2012-01-07 15:40
ToBeOOP
Rank: 3Rank: 3
等 级:论坛游侠
威 望:3
帖 子:106
专家分:181
注 册:2010-7-8
收藏
得分:0 
过了好久了..问题主要是input函数..
程序代码:
void input(void)

 {
      cout<<"Please enter nine scores before the training session."<<endl;
         double m = 0.0;
         int box1[9] ={0};
         int box[9] = {0};
         int t = 0;
         int flag = 0;
         for(int i=0;i != 3;i++)  {
             for(int j=0;j !=3;j++)
             {
                     cin>>m;   
                     if(m>0&&m<20)
                     {
                            a[i][j]=m;
                     }
             }
         }
         if(flag != 0) {
            cout<<"The Number"<<m<<" out of range,should be 0 to 20,Please enter again."<<endl;
         }

         AAAAAAAAAAAAAA
       
        cin.clear();
        cin.sync();
         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");

 }
这个是未完成的..但是你在A处..用循环在a数组中寻找值为0的值..然后在赋值就可以了..
2012-04-19 20:22
快速回复:新手求解!~~~ 请各位大侠进来看下 回车 和空格的区别 ?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013980 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved