hey guys i was solving a question but there is something which is not working properly.. I'll provide you guys with question statement and my code below.The problem is occuring after the loop like if the avg is more then 0 still it shows the output massege as "terminating". Can anyone please pin point the mistake and help me out with the problem. Urgent..!!
Your concern will highly be apreciated.. THANKYOU :)
QUESTION STATEMENT:
"Write a program that reads N numbers from the user and computes the average of only those numbers that are an even multiple of 3 and have 2 or 3 digits in them but are not divisible by 8. Also your program should terminate by displaying an error message if a negative number is entered."
MY CODE:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int limit;
cout<<" Please enter total number of entries you want to be processed.."<<endl;
cin>>limit;
int num;
int sum = 0;
double avg;
for(int i = 0; i<limit; i++)
{
cout<<"\n Please enter the number.."<<endl;
cin>>num;
if(num<0){
cout<<"Invalid input.. Please try again"<<endl;
break;
}else if((num % 3 == 0) && (num % 2 == 0) && (num % 8 != 0)){
sum = sum + num;
}
}
avg = sum / limit;
if(avg<= 0){
cout<<"terminating..!!"<<endl;
}else if(avg <= 999){
cout<<"The average of all the numbers is:\t"<<avg;
}else{
cout<<"The answer is bigger than the required condition"<<endl;
}
getch();
return 0;
}