我需要一个程序的帮助 [英] I need help with a program

查看:64
本文介绍了我需要一个程序的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Wrire一个程序,一次一个地询问用户一系列整数。当用户输入整数0时,程序显示以下信息。


1)系列中的整数数(不包括零)

2 )整数的平均值

3)系列中最大的整数

4)系列中的最小整数

5)范围(最大和最小整数之间的差异)


我到目前为止所有这一切都被卡住了。


#include< iostream.h>

#include< string.h>

#include< iomanip.h>


main( )

{

int number;

int number2;

int number3;

int total;

int average;

int counter;

int maximum;

int smallest = 130000;

int difference;

int addition;


do

{

cout<< 输入一系列整数,完成后输入0。 << ''\ n'';

cin>>数字;


if(number!= 0)

{

"Wrire a program that asks the user for a series of integers one at a time. When the user enters the integer 0, the program displays the following information.

1) the number of integers in the series (not including zero)
2) the average of the integers
3) the largest integer in the series
4) the smallest integer in the series
5) the range (difference between largest and smallest integer)

All I have is this so far, i''m stuck.

#include <iostream.h>
#include <string.h>
#include <iomanip.h>

main()
{
int number;
int number2;
int number3;
int total;
int average;
int counter;
int largest;
int smallest = 130000;
int difference;
int addition;

do
{
cout << "Enter a series of integers, enter 0 when you''re done." << ''\n'';
cin >> number;

if (number != 0)
{

推荐答案

当然你必须因为你在节目中的第一行错了所以被卡住了!

... cout<< 输入一系列整数,完成后输入0。 << ''\ n'';

cin>>数字;


如何从用户那里请求一系列整数然后只需要一个!!


你不能说cin>>数字;因为这只接受将要输入的第一个数字而忽略其余的数字?


而不是你应该说cout<<<"多少数字?"<< endl;

cin>> n;

cout<<" plz输入"<< endl;

For (int i = 0; i< n; i ++)

cin>> a [i];


其中n是他们的数字(12号4例子)和a [i]是你将存储这些数字的数组...

i希望你得到那么小的一部分...如果你需要更多帮助.......发布!
Sure You must be stuck since your first line in the program is wrong !!
... cout << "Enter a series of integers, enter 0 when you''re done." << ''\n'';
cin >> number;

how can you request a series of integers from a user and then expects only one !!

you can''t say cin>>number ; coz this will accepts only the first number that will be entered and ignores the rest ??

instead you should say cout<<"how many numbers ?"<<endl;
cin>>n;
cout<<"plz enter them "<<endl;
For (int i=0;i<n;i++)
cin>>a[i] ;

where n is their number ( 12 number 4 example) and a[i] is the array at which you will store these numbers ...
i hope you get that small part ...if u need more help .......post !


您确定它只接受一个号码吗?我看到其他人这样做了,他们完成了程序..它工作了!


顺便说一句,我正在使用do while循环编写这个程序。
Are you sure it will only accept one number? I saw someone else do it like that, and they finished the program.. and it worked!

By the way, im writing this program using a do while loop.


当然使用do while是另一回事...


使用任何循环都可以完成这项任务... for,while,do..while ,...

那你现在的问题是什么?
Of course Using a do while is a different matter ...

using any loop will do the job ... for ,while , do..while ,...
so what is your problem now ??


这篇关于我需要一个程序的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆