English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Can anyone write this program in C++ using a do while loop for me?

Write 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)

2006-10-28 14:17:26 · 7 answers · asked by jdk7212000 1 in Computers & Internet Programming & Design

7 answers

int a[100];
int x,n,av;
do{
cin>>x;
if (x!=0){
n++;
a[n]=x;
}
}while(x!=0);

int min,max;
cout< max=0;
av=0;
for(int i=0;i av=av+a[i+1];
if(a[i+1]>max){
max=a[i+1];
}
if(a[i+1] min=a[i+1];
}
}
cout< cout< cout< cout<

2006-10-28 16:30:30 · answer #1 · answered by vixklen 3 · 0 0

int a[100];
int x,n,av;
do{
cin>>x;
if (x!=0){
n++;
a[n]=x;
}
}while(x!=0);

int min,max;
cout< max=0;
av=0;
for(int i=0;i av=av+a[i+1];
if(a[i+1]>max){
max=a[i+1];
}
if(a[i+1] min=a[i+1];
}
}
cout< cout< cout< cout<

2006-10-30 18:30:25 · answer #2 · answered by luay k 1 · 0 0

Heh. I've got this written in Fortran95. Yes, I had it for homework, too.

It's not difficult.

2006-10-28 15:02:20 · answer #3 · answered by lordandmaker 3 · 0 1

for(int i = 0; i < temp.length(); ++i) characterCount(temp[i], letterCount); // pass each letter to characterCount() ----------------- You could just use temp.length() ------------------ For counting words use isalpha() to find the start of a word (and increment word counter) and isspace() to find the end of a word. It's a lot simpler.

2016-05-22 04:20:06 · answer #4 · answered by Anonymous · 0 0

You will not learn unless you do the assignment yourself.

2006-10-28 15:55:09 · answer #5 · answered by Mark M 2 · 1 1

Go to your room and do your homework.

2006-10-28 14:46:45 · answer #6 · answered by Lisa A 7 · 0 1

how much would you pay me to do your homework during the weekend?

2006-10-28 14:20:44 · answer #7 · answered by Manish 5 · 1 1

fedest.com, questions and answers