C++编程的code

来源:百度知道 编辑:UC知道 时间:2024/06/18 17:27:32
Write a program that uses a sentinel-based input loop to read three values representing feet, converts feet to meters (1 foot = 0.3048 meter), and displays all values with appropriate labels.

这是题目。不会……拜托高手帮帮忙……该怎么写?最好能讲解一下for 循环之类被用到的语句
因为是英语教学,我不知道C++有没有中文版的,不知道编的时候会不会哪有区别。就是输入三个数,表示的是三个英尺(feet)为单位的长度,然后编出的程序将它们换算成米)(meter)。
还没学到float,看到有人好像输的是int main,而且for 循环好像在开头,这样写的for(;;)而且好像声明还有<cmath>
应该是三个任意数,不是三个连续的数。

#include<iostream.h>

void main()
{
double foot, meter;//英尺值,米值

for(int i=0; i<3; i++) //执行3次
{
cout<<"请输入一个英尺数: "<<endl; //输出一个提示字符窜
foot = 0;
meter = 0; //赋初值
cin>>foot; //输入一个英尺数
meter = foot * 0.3048; //转换成米数
cout<<foot<<"英尺等于"<<meter<<"米"<<endl; //输出结果
}

}

先翻译成中文的

不会说汉语吗?

#include <iostream>
using namespace std;
int main()
{
float a[4]={0};//浮点型数组
int i;
for(i=1;i<=3;i++) //分别读入
cin >> a[i];
for(i=1;i<=3;i++)
cout << a[i] * 0.3048 <<endl; //乘进制输出
system("pause");
return 0;
}