I need to create a C program that allows the user to enter a
I need to create a C++ program that allows the user to enter a set of integers and then show a summary of the info as the pic shows. If the user enters 0 the loop is exited. Thanks!
Enter a Number (0 to stop) 12 Enter a Number (0 to stop) 4 Enter a Number (0 to stop): -1 Enter a Number (0 to stop) -5 Enter a Number (0 to stop): 18 Enter a Number (0 to stop) 0 of positives 3 of negatives 2 Suma 28 Average 5.60 Solution
#include<iostream>
using namespace std;
int main()
{
int a,p=0, n=0,sum=0,avg=0;
while(1)
{
cout<<\"Enter any Number(0 to stop) : \";
cin>>a;
if(a == 0)
break;
else
{
(a>0)?p++:n++;
sum += a;
}
}
cout<< \"# of positives = \"<< p;
cout<<\"# of negatives = \"<<n;
cout<<\"sum = \" <<sum;
avg = sum/(p+n);
cout<<\"average = \"<< avg;
return 0;
