Jun 17, 2014 at 12:55pm UTC
This program is so ridiculously long, I wanted to know if there is shorter way to make this program work. Also, the program was over 30000 characters long so what's missing doesn't really matter I just want to know if this part of the program can be shortened. Btw don't mind the "gotoxy" or "txtcolor" it's part of a header file "iocolors" it's made to make the program look nice.
#include <iostream.h>
#include <conio.h>
#include <apstring.cpp>
#include <iocolors.h>
numbus = numbus++;
gotoxy (1, 1);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 2);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 3);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 4);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 5);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 6);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
break;
case 7:
numbus = numbus++;
gotoxy (1, 1);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 2);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 3);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 4);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 5);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 6);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 7);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
break;
case 8:
numbus = numbus++;
gotoxy (1, 1);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 2);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 3);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 4);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 5);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 6);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 7);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 8);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
break;
case 9:
numbus = numbus++;
gotoxy (1, 1);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 2);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 3);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 4);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 5);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 6);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 7);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 8);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 9);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
break;
case 10:
numbus = numbus++;
gotoxy (1, 1);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 2);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 3);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 4);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 5);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 6);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 7);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 8);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 9);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
numbus = numbus++;
gotoxy (1, 10);
cout << "Bus " << numbus;
cout << " is assigned to " << groupname << ".";
break;
getch ();
cin.ignore (80, '\n');
runProgram = runProgram - 1;
}
while (runProgram >= 1);
}
Jun 17, 2014 at 1:22pm UTC
Most of what you have there could be replaced by a simple loop, something like this:
1 2 3 4 5 6
for (int row=1; row<=n; row++)
{
gotoxy (1, row);
cout << "Bus " << ++numbus
<< " is assigned to " << groupname << "." ;
}
n
in my code is whatever variable you use in the switch-case
Or of you want to really reduce the number of lines (but probably less readable), the entire switch-case block of over 240 lines or more than 6000 characters of text could be replaced with just two lines:
1 2
for (int row=1; row<=n; row++)
gotoxy (1, row), cout << "Bus " << ++numbus << " is assigned to " << groupname << "." ;
Last edited on Jun 17, 2014 at 2:40pm UTC
Jun 18, 2014 at 11:38am UTC
How would I put that code into my program without getting any errors?
Jun 18, 2014 at 11:53am UTC
Nevermind, Thanks so much! You have saved me from tons of lines of code.
Jun 18, 2014 at 1:21pm UTC
Glad that was useful. It did occur to me based in this part, that there may be other parts of your code which could be shortened too.