newbie programming question
is there a better way to write this code?
// high score
#include <iostream.h>
void main()
{
int playersScore = 0;
int highScore[10] = {10525,9832,8145,6445,4540,3834,3106,2536,1879,928}; // default scores
int c = 0;
cout <<"High Scores\n";
do
{
cout <<"\n" <> playersScore;
if (playersScore < highScore[9])
cout <<"YOU SUCK!!!\n\n";
while (playersScore > highScore[9])
{
if (playersScore > highScore[0])
{
highScore[9] = highScore[8];
highScore[9] = highScore[8];
highScore[8] = highScore[7];
highScore[7] = highScore[6];
highScore[6] = highScore[5];
highScore[5] = highScore[4];
highScore[4] = highScore[3];
highScore[3] = highScore[2];
highScore[2] = highScore[1];
highScore[1] = highScore[0];
highScore[0] = playersScore;
break;
}
if (playersScore > highScore[1])
{
highScore[9] = highScore[8];
highScore[9] = highScore[8];
highScore[8] = highScore[7];
highScore[7] = highScore[6];
highScore[6] = highScore[5];
highScore[5] = highScore[4];
highScore[4] = highScore[3];
highScore[3] = highScore[2];
highScore[2] = highScore[1];
highScore[1] = playersScore;
break;
}
if (playersScore > highScore[2])
{
highScore[9] = highScore[8];
highScore[9] = highScore[8];
highScore[8] = highScore[7];
highScore[7] = highScore[6];
highScore[6] = highScore[5];
highScore[5] = highScore[4];
highScore[4] = highScore[3];
highScore[3] = highScore[2];
highScore[2] = playersScore;
break;
}
if (playersScore > highScore[3])
{
highScore[9] = highScore[8];
highScore[8] = highScore[7];
highScore[7] = highScore[6];
highScore[6] = highScore[5];
highScore[5] = highScore[4];
highScore[4] = highScore[3];
highScore[3] = playersScore;
break;
}
if (playersScore > highScore[4])
{
highScore[9] = highScore[8];
highScore[8] = highScore[7];
highScore[7] = highScore[6];
highScore[6] = highScore[5];
highScore[5] = highScore[4];
highScore[4] = playersScore;
break;
}
if (playersScore > highScore[5])
{
highScore[9] = highScore[8];
highScore[8] = highScore[7];
highScore[7] = highScore[6];
highScore[6] = highScore[5];
highScore[5] = playersScore;
break;
}
if (playersScore > highScore[6])
{
highScore[9] = highScore[8];
highScore[8] = highScore[7];
highScore[7] = highScore[6];
highScore[6] = playersScore;
break;
}
if (playersScore > highScore[7])
{
highScore[9] = highScore[8];
highScore[8] = highScore[7];
highScore[7] = playersScore;
break;
}
if (playersScore > highScore[8])
{
highScore[9] = highScore[8];
highScore[8] = playersScore;
break;
}
if (playersScore > highScore[9])
{
highScore[9] = playersScore;
break;
}
}
cout <<"\n\nHIGH SCORES";
do
{
cout <<"\n" <<c+1 << "\t" << highScore[c];
c++;
}
while (c < 10);
cout <<endl;
}
// high score #include <iostream.h>void main(){ int playersScore = 0; int highScore[10] = {10525,9832,8145,6445,4540,3834,3106,2536,1879,928}; // default scores int c = 0; cout <<"High Scores\n"; do { cout <<"\n" <<c+1 << "\t" << highScore[c]; c++; } while (c < 10); c=0; cout <<"\nEnter players score :"; cin >> playersScore; if (playersScore < highScore[9]) cout <<"YOU SUCK!!!\n\n"; for( c=9; c>=0; c++ ) // notice the c++ LoL { if( playersScore > highScore[c] ) { for( int i=c ; i>0 ; i-- ) // here was the error, it was "i++" instead of "i--" highScore[i-1] = highScrore[i]; highScore[c] = playersScore; break; } } c = 0; cout <<"\n\nHIGH SCORES"; do { cout <<"\n" <<c+1 << "\t" << highScore[c]; c++; } while (c < 10); cout <<endl;}
I think there's no errors...
[Edit] An error fixed
KaMiKaZe
[edited by - Kamikaze15 on January 15, 2003 8:29:46 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement