Answer to Question #18324 in C++ for thandy

Question #18324
write a program that accepts a list of numbers from a user until a number is repeated. the program then prints out the number of numbers entered(excluding the last and their sum). e.g numbers 5,-6,0,45,45. four numbers entered and their sum is 44
1
Expert's answer
2012-11-13T04:41:00-0500
#include <stdio.h>
#include <iostream.h>

void main(){
int i=0, k, sum=0, check=1, a[100];
while (check){
& cout<<"enter a number: ";
& cin>>a[i];
& if ((i!=1)&&(a[i-1]==a[i])) check=0;
& i++;
}
for (k=0;k<i-1;k++) sum+=a[k];
cout<<i-1<<" numbers entered\n"<<"their sum is "<<sum<<"\n";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS