Solutions

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

About the author

Syed Moin Ali

Hello My Name is Syed Moin Ali and I am the founder of PC Learnings Here on this blog I write about Blogging, SEO, Internet Tricks, Social Networking Site, and Make Money

Add Comment

Click here to post a comment