In: Computer Science
Design and implement a C++ program that performs the following steps:Ask the user to enter a positive integer number N; Your program may need to prompt the user to enter many times until it reads in a positive number;Let user to enter N (obtained in the previous step) floating point numbers, and count how many positive ones there are in the sequence and sum up these positive numbers; (Hint: negative numbers or 0 are ignored).Display result.You can and should use functions in this program. For example, you should implement a function that reads a positive integer numbers from the user and returns the number.In this program, you can safely assume that user will always enter the right type data (e.g., integers for integer input and real numbers for floating point number input).Compile and test your program to make sure there is no syntax or logical errors in it.
here is the required solution
here is the code
#include <iostream>
using namespace std;
int read_positive_number()
{
int num=-2;
while(num<1)
{
cout<<"Enter number:\n";
cin>>num;
}
return num;
}
int main()
{ int n,num,sum=0;
cout<<"Enter how many numbers you want:\n";
cin>>n;
for(int i=0;i<n;i++)
{
num=read_positive_number();
sum=sum+num;
}
cout<<"sum of "<<n<<" positive numbers are
"<<sum;
return 0;
}