-
September 6th, 2012, 11:53 AM
#1
Where did i go wrong??
i wrote this program using Dev++ but it only freezes when it runs, where did i go wrong??
Here's the code:
#include<iostream>
using namespace std;
int main(){
int numbers;
int counter1=0;
int counter2=0;
cout<<"enter numbers, 0 to stop the program and display the result"<<endl;
cin>>numbers;
while(numbers!=0){
if(numbers<0){
counter1 = counter1+1;
}
else
counter2=counter2+1;
if(number==0){
cout<<"you have entered "<<counter1<<" Negative numbers!""<<endl;
}
return 0;
system("pause");
}
}
-
September 6th, 2012, 12:11 PM
#2
Re: Where did i go wrong??
That code didn't compile. Fixing the compile errors, this is what your code looks like properly formatted. Logic errors should be obvious.
Code:
#include<iostream>
using namespace std;
int main()
{
int numbers;
int counter1=0;
int counter2=0;
cout<<"enter numbers, 0 to stop the program and display the result"<<endl;
cin>>numbers;
while(numbers!=0)
{
if(numbers < 0)
{
counter1 = counter1+1;
}
else
counter2=counter2+1;
if(numbers ==0 )
{
cout<<"you have entered "<<counter1<<" Negative numbers!"<<endl;
}
return 0;
system("pause");
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|