C++编程的小问题- -0
请看看下面两个程序有什么错误- -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.
}
回复: 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()
{
// declarationof 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;
}
回复: C++编程的小问题- -0
请看看下面两个程序有什么错误- -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.
}
int howmany // How many values to sum.
这一行少一个分号。改成:
int howmany; // How many values to sum.
回复: 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()
{
// declarationof 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;
}
cin>> inch
少分号。
cin>> inch;
回复: C++编程的小问题- -0
楼主编译一下就知道问题出在哪里了啊!这样看……我实在没兴趣……编译器不是会提示的啊?第几行第几行有错误!回复: C++编程的小问题- -0
我是人工编译器~~回复: C++编程的小问题- -0
已经OK了,谢谢STAR~~PS:5楼的老兄,你没兴趣就表灌水了,OK?
斑竹可以锁了
页:
[1]