找回密码
 注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

扫一扫,访问微社区

快捷导航
事务所专题-柯南20周年纪念事件簿
搜索
查看: 654|回复: 6
打印 上一主题 下一主题

C++编程的小问题- -0

 关闭 [复制链接]

名侦探

水区荣誉版主
草莓 BRAVO
晓の朱雀

0

主题

0

好友

398

积分

 

升级
27%
帖子
10587
精华
4
积分
398
威望
178
RP
286
金钱
173 柯币
人气
0 ℃
注册时间
2003-3-1
跳转到指定楼层
顶楼
发表于 2004-9-16 07:55:38 |只看该作者 |倒序浏览
请看看下面两个程序有什么错误- -0

/*
*          File: sum.cpp
*        Author: Robert I. Pitts <[email protected]>
* Last Modified: January 27, 2000
*         Topic: Using Emacs for Programming - Compiling
*   Modified by: I. Couloigner <[email protected]> in July 3, 2003
* ------------------------------------------------------------------------
*
* Usage:
* =====
* The user first enters how many numbers need to be summed and
* hits <RETURN>.  Then, the user enters each of the numbers on a
* separate line.  Finally, the sum of the numbers is printed.
*/


#include <iostream>
using namespace std;

int main()
{
  int howmany       // How many values to sum.
  float sum = 0.0;  // The running sum.

  // Ask the user and get how many numbers to read.
  cout << "Enter how many numbers I will sum: ";
  cin >> howmany;

    for (int i = O; i < howmany; i++)
        {
      float value;  // The current value.

  // Read the ith number.
      cout << "Enter number: " ;
      cin >> value;
   
   // Increment the sum.
      sum += value;
          
        }

  // prompt the result
  cout << "The sum is: " << sum << endl;

  cout << "Thank you for using the summer!" << endl;

  return 0;  // 0 means program exited successfully.
}

名侦探

水区荣誉版主
草莓 BRAVO
晓の朱雀

0

主题

0

好友

398

积分

 

升级
27%
帖子
10587
精华
4
积分
398
威望
178
RP
286
金钱
173 柯币
人气
0 ℃
注册时间
2003-3-1
沙发
发表于 2004-9-16 07:58:05 |只看该作者

回复: C++编程的小问题- -0

这是第2个...

// Engg 233 Lab1
// File lab1_32.cc
// Author: I. Couloigner, aka Dr.C
// Created: July 21, 2004
// Topic: converts feet, inches in centimetres (1 inch = 2.54 cm)

#include <iostream>
using namespace std;

// main program
int main()
{
        // declaration  of variables
        // input variables
        int feet, inch;
        // temporary variable
        int inches;
        // output variable
        double cm;

        // input from user
        cout << "Please enter your data: ";
        cout << "\n\t feet = ";
        cin >> feet;
        cout << "\t inch = ";
        cin>> inch

        // computes total number of inches
        tot_inches = inch + feet*12;

        // conversion into centimetres
        cm = inch * 2.54;

        // display result
        cout << "\n" << feet << " feet and " << inch << " inches are equal to "
                << cm << " cm.\n" << endl;

        return 0;
}
回复

使用道具 举报

推理爱好者

事务所程序组

0

主题

0

好友

119

积分

 

升级
98%
帖子
389
精华
0
积分
119
威望
14
RP
252
金钱
510 柯币
人气
0 ℃
注册时间
2003-10-14
板凳
发表于 2004-9-16 10:21:04 |只看该作者

回复: C++编程的小问题- -0

[QUOTE=shxyfan]请看看下面两个程序有什么错误- -0

/*
*          File: sum.cpp
*        Author: Robert I. Pitts <[email protected]>
* Last Modified: January 27, 2000
*         Topic: Using Emacs for Programming - Compiling
*   Modified by: I. Couloigner <[email protected]> in July 3, 2003
* ------------------------------------------------------------------------
*
* Usage:
* =====
* The user first enters how many numbers need to be summed and
* hits <RETURN>.  Then, the user enters each of the numbers on a
* separate line.  Finally, the sum of the numbers is printed.
*/


#include <iostream>
using namespace std;

int main()
{
  int howmany       // How many values to sum.
  float sum = 0.0;  // The running sum.

  // Ask the user and get how many numbers to read.
  cout << "Enter how many numbers I will sum: ";
  cin >> howmany;

    for (int i = O; i < howmany; i++)
        {
      float value;  // The current value.

  // Read the ith number.
      cout << "Enter number: " ;
      cin >> value;
   
   // Increment the sum.
      sum += value;
          
        }

  // prompt the result
  cout << "The sum is: " << sum << endl;

  cout << "Thank you for using the summer!" << endl;

  return 0;  // 0 means program exited successfully.
}[/QUOTE]
   int howmany       // How many values to sum.
这一行少一个分号。改成:
  int howmany;      // How many values to sum.
我蹦,我跳,你们抓不到我!:)
回复

使用道具 举报

推理爱好者

事务所程序组

0

主题

0

好友

119

积分

 

升级
98%
帖子
389
精华
0
积分
119
威望
14
RP
252
金钱
510 柯币
人气
0 ℃
注册时间
2003-10-14
地板
发表于 2004-9-16 10:25:43 |只看该作者

回复: C++编程的小问题- -0

[QUOTE=shxyfan]这是第2个...

// Engg 233 Lab1
// File lab1_32.cc
// Author: I. Couloigner, aka Dr.C
// Created: July 21, 2004
// Topic: converts feet, inches in centimetres (1 inch = 2.54 cm)

#include <iostream>
using namespace std;

// main program
int main()
{
        // declaration  of variables
        // input variables
        int feet, inch;
        // temporary variable
        int inches;
        // output variable
        double cm;

        // input from user
        cout << "Please enter your data: ";
        cout << "\n\t feet = ";
        cin >> feet;
        cout << "\t inch = ";
        cin>> inch

        // computes total number of inches
        tot_inches = inch + feet*12;

        // conversion into centimetres
        cm = inch * 2.54;

        // display result
        cout << "\n" << feet << " feet and " << inch << " inches are equal to "
                << cm << " cm.\n" << endl;

        return 0;
}[/QUOTE]
cin>> inch
少分号。
cin>> inch;
我蹦,我跳,你们抓不到我!:)
回复

使用道具 举报

资源补档组荣誉
快报区荣誉版主
倉木麻衣の大ファン

0

主题

0

好友

1542

积分

 

帖子
15138
精华
16
积分
1542
威望
873
RP
1295
金钱
1000 柯币
人气
8 ℃
注册时间
2004-8-11
5
发表于 2004-9-16 12:28:41 |只看该作者

回复: C++编程的小问题- -0

楼主编译一下就知道问题出在哪里了啊!这样看……我实在没兴趣……编译器不是会提示的啊?第几行第几行有错误!
约定
兰~我一生唯一爱的女孩,我会照顾你一辈子
回复

使用道具 举报

推理爱好者

事务所程序组

0

主题

0

好友

119

积分

 

升级
98%
帖子
389
精华
0
积分
119
威望
14
RP
252
金钱
510 柯币
人气
0 ℃
注册时间
2003-10-14
6
发表于 2004-9-16 20:17:41 |只看该作者

回复: C++编程的小问题- -0

我是人工编译器~~
回复

使用道具 举报

名侦探

水区荣誉版主
草莓 BRAVO
晓の朱雀

0

主题

0

好友

398

积分

 

升级
27%
帖子
10587
精华
4
积分
398
威望
178
RP
286
金钱
173 柯币
人气
0 ℃
注册时间
2003-3-1
7
发表于 2004-9-17 08:50:46 |只看该作者

回复: C++编程的小问题- -0

已经OK了,谢谢STAR~~
PS:5楼的老兄,你没兴趣就表灌水了,OK?
斑竹可以锁了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册 新浪微博登陆

手机版|Archiver|名侦探柯南事务所 ( 沪ICP备17027512号 )

GMT+8, 2024-9-22 07:41 , Processed in 0.032521 second(s), 15 queries , MemCached On.

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部