C++ Errors

Joined
Sep 18, 2007
Messages
9
Reaction score
0
Points
1
Ok I have just ended up talking to myself on this thing. I forgot to put two = in the if statement (n1==n2).

[old]Nevermind about the "I can figure it out." I want it to tell me if I enter the first number I entered more than once. It tells me the number is repeated 9 times no matter what.

Code:
#include <iostream>
using namespace std;
int main()
{
        int n1, n2, i, a;
        i=2;
        a=0;
        cout<<"Enter Number 1"<<endl;
        cin>>n1;
        while (i<11)
        {
                cout<<"Enter Number "<<i<<endl;
                cin>>n2;
                if (n2=n1)
                {
                        a=a+1;
                }
                i=i+1;
        }
        if (a>0)
        {
                cout<<n1<<" is repeated "<<a<<" times"<<endl;
        }
        else
        {
                cout<<n1<<" is not repeated"<<endl;
        }
        return 0;
}

This is the old post if anyone is interested.

Ok, I forgot "using namespace std;", so nevermind. Just incase you were wondering, it does not work properly, but I can figure that part out.


I am try to write a simple programe. You enter ten numbers, and it tells you if you entered the first number you entered more than once.[/old]
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top