CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2012
    Posts
    4

    Exclamation 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");

    }
    }

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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
  •  





Click Here to Expand Forum to Full Width

Featured