Accept Number till negative number is not entered
#include<iostream.h>
#include<conio.h>
void main()
{
int n;
clrscr();
do
{
cout<<"Enter number: ";
cin>>n;
}
while( n >= 0);
}
Accept Number till user say 'No'
#include<iostream.h>
#include<conio.h>
void main()
{
int n;
char ch = 'Y', ans, k = 'y';
clrscr();
do
{
cout<<"Enter number: ";
cin>>n;
cout<<"Do you want to continue";
cout<<"\nThe answer is: ";
cin>>ans;
}
while( ans == ch || k == ans);
}
Accept addition of Numbers till sum is even
#include<iostream.h>
#include<conio.h>
void main()
{
int a, b, sum;
clrscr();
do
{
cout<<"Enter number: ";
cin>>a>>b;
sum = a + b;
cout<<"Sum is: "<<sum;
}
while( sum % 2 == 0);
}
Accept Number till negative number is not entered & print sum of all positive numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int no, sum = 0;
clrscr();
do
{
cout<<"Enter number: ";
cin>>no;
if( no >= 0)
sum = sum + no;
}
while( no >= 0);
cout<<"Sum of all positive numbers is: "<<sum;
}