找回密码
 注册

新浪微博登陆

只需一步, 快速开始

QQ登录

只需一步,快速开始

快捷导航
事务所专题-柯南20周年纪念事件簿
搜索
查看: 367|回复: 6

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

  [复制链接]

杯户小学生

发表于 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.
}

杯户小学生

 楼主| 发表于 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;
}
回复 喝彩 无视

使用道具 举报

杯户小学生

发表于 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.
回复 喝彩 无视

使用道具 举报

杯户小学生

发表于 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;
回复 喝彩 无视

使用道具 举报

事务所资源补档组

发表于 2004-9-16 12:28:41 | 显示全部楼层

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

楼主编译一下就知道问题出在哪里了啊!这样看……我实在没兴趣……编译器不是会提示的啊?第几行第几行有错误!
回复 喝彩 无视

使用道具 举报

杯户小学生

发表于 2004-9-16 20:17:41 | 显示全部楼层

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

我是人工编译器~~
回复 喝彩 无视

使用道具 举报

杯户小学生

 楼主| 发表于 2004-9-17 08:50:46 | 显示全部楼层

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

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

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|名侦探柯南事务所 ( 沪ICP备05038770号 )

GMT+8, 2025-2-1 16:41 , Processed in 0.096856 second(s), 17 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表