76 255
Assignments Done
Successfully Done
In May 2019

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
Expert's answer
#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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions