Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ program

Name: Anonymous 2010-03-10 20:06

Made a short program that takes numbers, puts them into an array and compares them with each other. If any of your numbers are the same it gets you to type the numbers in again. This code seems to work fine but I though it's quite a lot for just comparing numbers, is there an easier/shorter way of comparing multiple numbers like this?

#include <iostream>
#include <ctime>
using namespace std;

int main()
{
int count, test, mine[7], machine[7], count1, count2;
srand(time(NULL));
test=0;
count1=1;
count2=0;

while (test<1) {
     labelA:
    for (count=1;count<7;count++) {
        cout<<"Enter Number "<<count<<endl;
        cin>>mine[count];
        }
        while (count1<6) {
            for (count2=2;count2<7;count2++) {
                if (mine[count1]==mine[count2]) {
                    goto  labelA;
                    }
                    }
                    count1++;
                    for (count2=2;count2<7;count2++) {
                        if (mine[count1]==mine[count2]) {
                            goto  labelA;
                            }
                            }
                            count1++;
                            for (count2=3;count2<7;count2++) {
                                if (mine[count1]==mine[count2]) {
                                    goto  labelA;
                                    }
                                    }
                                    count1++;
                                    for (count2=4;count2<7;count2++) {
                                        if (mine[count1]==mine[count2]) {
                                            goto  labelA;
                                            }
                                            }
                                            count1++;
                                            for (count2=2;count2<7;count2++) {
                                                if (mine[count1]==mine[count2]) {
                                                    goto  labelA;
                                                    }
                                                    }
                                                    count1++;
                                                    test++;
                                                    }
                                                    }
return 0;
}

Name: Anonymous 2010-03-18 19:06

>>27
Any program that outputs the response "You matched balls" worries me.

int i = 0, j = 0;
int mine[] = { 0, 0, 0, 0, 0, 0 };
for(; i < 6; i++)
{
   cout<<"Enter Number "<<(i+1)<<": ";
   cin>>mine[i];
   if(mine[i] == 0 || mine[i] > 49)
   {
      cout<<"Duplicate in 'mine' numbers.  Start over ..."<<endl;
      i = -1;
      continue; // restarts this outer for() loop
   }
   if(i > 0)
   {
      for(j = 0; j < i; j++)
      {
         if(mine[i] == mine[j])
         {
            cout<<"Duplicate in 'mine' numbers.  Start over ..."<<endl;
            i = -1;
            break; // exits this inner for() loop
         }
      }
   }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List