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;
}
#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;
}