[gtranslate]

prog

Input Numbers Until -ive # Entered & Count| if Condition | C++

Write a program that inputs numbers from the user till the user inputs a negative number. The program should then print the total number of times the number 1 was

Coding

#include<iostream>
using namespace std;
int main()
{
      int i = 1;
      int j=0;
     cout<<“Please enter a number, and When finished, enter a negative number = “<<endl;
      while(i >= 0)
                                {
                                cout<<“Enter a number = “;
                                cin>>i;
         
                if(i==1)
                                {
                                                j=j+1;
                                                                }
                                }
                cout<<“\n1 Was Inputed “<<j<<” Times”;
                return 0;
}

Output

prog C++ solution