well my code is pretty hefty so far, so illl give you the base,
Code:cout << "which week : ";
cin << bookings[i].week;
cout << "which day : ";
cin << bookings[i].day;
cout << "which period :";
cin << bookings[i].period;
i++
Printable View
well my code is pretty hefty so far, so illl give you the base,
Code:cout << "which week : ";
cin << bookings[i].week;
cout << "which day : ";
cin << bookings[i].day;
cout << "which period :";
cin << bookings[i].period;
i++
I take it that monday is day 1, tuesday 2 etc.
and period 1 is 1 etc.
correct.
It seems that my code is pretty big...can you post your attempt?
well it sort of goes like this but it aint finished.
you sort of get what i mean.Code:for(i=0; i<number_of_bookings; i++){
switch(bookings[i].week){
case 1:
switch(bookings[i].day)
{
case 1:
switch(bookings[i].time)
{
case 1: mp1 += 1; break;
case 2: mp2 += 1; break;
case 3:
case 4:
}
case 2:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 3:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 4:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 5:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 6:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
}
case 2:
switch(bookings[i].day)
{
case 1:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 2:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 3:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 4:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 5:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 6:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
}
case 3:
switch(bookings[i].day){
case 1:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 2:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 3:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 4:
switch(bookings[i].time)
{
case 1:
case 2:
case 3:
case 4:
}
case 5:
switch(bookings[i].time){
case 1:
case 2:
case 3:
case 4:
case 6:
switch(bookings[i].time){
case 1:
case 2:
case 3:
case 4:
case 4:
switch(bookings[i].day){
case 1:
switch(bookings[i].time){
case 1:
case 2:
case 3:
case 4:
case 2:
switch(bookings[i].time){
case 1:
case 2:
case 3:
case 4:
case 3:
switch(bookings[i].time){
case 1:
case 2:
case 3:
case 4:
case 4:
switch(bookings[i].time){
case 1:
case 2:
case 3:
case 4:
case 5:
switch(bookings[i].time){
case 1:
case 2:
case 3:
case 4:
case 6:
switch(bookings[i].time){
case 1:
case 2:
case 3:
case 4:
cout << mp1/(number of mp1s)*100 << endl;
Nah my way ended up being really long aswell...my calculation at the end is probably really wrong as I couldn't remember how many of each period there were meant to be.Code:int monday[4];
int tuesday[4];
int wednesday[4];
int thursday[4];
int friday[4];
int saturday[4];
int dayx;
int periodx;
for (int x = 0; x < 50; x++) {
dayx = bookings[x].day;
periodx = bookings[x].time;
if (dayx == 1) {
switch (periodx) {
case 1:
monday[0]++;
break;
case 2:
monday[1]++;
break;
case 3:
monday[2]++;
break;
case 4:
monday[3]++;
break;
default:
return 0;
}
}
if (dayx == 2) {
switch (periodx) {
case 1:
tuesday[0]++;
break;
case 2:
tuesday[1]++;
break;
case 3:
tuesday[2]++;
break;
case 4:
tuesday[3]++;
break;
default:
return 0;
}
}
if (dayx == 3) {
switch (periodx) {
case 1:
wednesday[0]++;
break;
case 2:
wednesday[1]++;
break;
case 3:
wednesday[2]++;
break;
case 4:
wednesday[3]++;
break;
default:
return 0;
}
}
if(dayx == 4) {
switch (periodx) {
case 1:
thursday[0]++;
break;
case 2:
thursday[1]++;
break;
case 3:
thursday[2]++;
break;
case 4:
thursday[3]++;
break;
default:
return 0;
}
}
if(dayx == 5) {
switch (periodx) {
case 1:
friday[0]++;
break;
case 2:
friday[1]++;
break;
case 3:
friday[2]++;
break;
case 4:
friday[3]++;
break;
default:
return 0;
}
}
if(dayx == 6) {
switch (periodx) {
case 1:
saturday[0]++;
break;
case 2:
saturday[1]++;
break;
case 3:
saturday[2]++;
break;
case 4:
saturday[3]++;
break;
default:
return 0;
}
}
}
cout << "Monday 1: " << (100/9)*monday[0] << "%" << endl;
cout << "Monday 2: " << (100/9)*monday[1] << "%" << endl;
cout << "Monday 3: " << (100/9)*monday[2] << "%" << endl;
cout << "Monday 4: " << (100/9)*monday[3] << "%" << endl;
cout << "Tuesday 1: " << (100/9)*tuesday[0] << "%" << endl;
cout << "Tuesday 2: " << (100/9)*tuesday[1] << "%" << endl;
cout << "Tuesday 3: " << (100/9)*tuesday[2] << "%" << endl;
cout << "Tuesday 4: " << (100/9)*tuesday[3] << "%" << endl;
cout << "Wednesday 1: " << (100/9)*wednesday[1] << "%" << endl;
thats a good effort bumfluff. gave me a few ideas to think about there with the arrays. however my is just gettin longer and longer. there must be an easier solution!
Yeah I thought the arrays was pretty clever :)
I think that after I had written that I was about to grasp a way of cutting out all of those switch statements...but excessive amounts of Geography have since knocked the thought out of me.
Here I didn't check the syntax, but you can make an easier 2d array and use a loop for all the if statements. Theres more that could be done, for example check the second code.
Code:int day[7][4];
int dayx;
int periodx;
for (int i = 0; i < 50; ++i) {
dayx = bookings[i].day;
periodx = bookings[i].time;
for(int j = 0; j < 6; ++j) {
if (dayx == j) {
switch (periodx) {
case 1:
++day[j][0];
break;
case 2:
++day[j][1];
break;
case 3:
++day[j][2];
break;
case 4:
++day[j][3];
break;
default:
return 0;
}
}
}
}
cout << "Monday 1: " << (100/9)*day[0][0] << "%" << endl;
cout << "Monday 2: " << (100/9)*day[0][1] << "%" << endl;
cout << "Monday 3: " << (100/9)*day[0][2] << "%" << endl;
cout << "Monday 4: " << (100/9)*day[0][3] << "%" << endl;
cout << "Tuesday 1: " << (100/9)*day[1][0] << "%" << endl;
cout << "Tuesday 2: " << (100/9)*day[1][1] << "%" << endl;
cout << "Tuesday 3: " << (100/9)*day[1][2] << "%" << endl;
cout << "Tuesday 4: " << (100/9)*day[1][3] << "%" << endl;
cout << "Wednesday 1: " << (100/9)*day[2][1] << "%" << endl;
Code:int day[7][4];
int dayx;
int periodx;
for (int i = 0; i < 50; ++i) {
dayx = bookings[i].day;
periodx = bookings[i].time;
for(int j = 0; j < 6; ++j) {
if (dayx == j) {
if(!periodx) return 0;
++day[j][--periodx];
}
}
}
cout << "Monday 1: " << (100/9)*day[0][0] << "%" << endl;
cout << "Monday 2: " << (100/9)*day[0][1] << "%" << endl;
cout << "Monday 3: " << (100/9)*day[0][2] << "%" << endl;
cout << "Monday 4: " << (100/9)*day[0][3] << "%" << endl;
cout << "Tuesday 1: " << (100/9)*day[1][0] << "%" << endl;
cout << "Tuesday 2: " << (100/9)*day[1][1] << "%" << endl;
cout << "Tuesday 3: " << (100/9)*day[1][2] << "%" << endl;
cout << "Tuesday 4: " << (100/9)*day[1][3] << "%" << endl;
cout << "Wednesday 1: " << (100/9)*day[2][1] << "%" << endl;
Aha yes...I was part of the way there really...maybe my mysterious notion was 2D arrays.
thanks for your help guys, that algo came a little too late im afraid (was fast asleep in the mysterious world of C) cause ive got one to work and ive already included it into my documention which is now fully annotated.
out of curiosity here it is, not quite as good as dae's but hey.
Code:for(i=0; i<number_of_bookings; i++){
switch(bookings[i].day)
{
case 1:
switch(bookings[i].time)
{
case 1: monp1 += 1; break;
case 2: monp2 += 1; break;
case 3: monp3 += 1; break;
case 4: monp4 += 1; break;
}
break;
case 2:
switch(bookings[i].time)
{
case 1: tuep1 += 1; break;
case 2: tuep2 += 1; break;
case 3: tuep3 += 1; break;
case 4: tuep4 += 1; break;
}
break;
case 3:
switch(bookings[i].time)
{
case 1: wedp1 += 1; break;
case 2: wedp2 += 1; break;
case 3: wedp3 += 1; break;
case 4: wedp4 += 1; break;
}
break;
case 4:
switch(bookings[i].time)
{
case 1: thup1 += 1; break;
case 2: thup2 += 1; break;
case 3: thup3 += 1; break;
case 4: thup4 += 1; break;
}
break;
case 5:
switch(bookings[i].time)
{
case 1: frip1 += 1; break;
case 2: frip2 += 1; break;
case 3: frip3 += 1; break;
case 4: frip4 += 1; break;
}
break;
case 6:
switch(bookings[i].time)
{
case 1: satp1 += 1; break;
case 2: satp2 += 1; break;
case 3: satp3 += 1; break;
case 4: satp4 += 1; break;
}
break;
}
}
cout << "Monday Period 1 : " << (100/9) * monp1 << " % " << endl;
cout << "Period 2 : " << (100/9) * monp2 << " % " << endl;
cout << "Period 3 : " << (100/9) * monp3 << " % " << endl;
cout << "Period 4 : " << (100/9) * monp4 << " % " << endl;
cout << "Tuesday Period 1 : " << (100/9) * tuep1 << " % " << endl;
cout << "Period 2 : " << (100/9) * tuep2 << " % " << endl;
cout << "Period 3 : " << (100/9) * tuep3 << " % " << endl;
cout << "Period 4 : " << (100/9) * tuep4 << " % " << endl;
cout << "Wednesday Period 1 : " << (100/8) * wedp1 << " % " << endl;
cout << "Period 2 : " << (100/8) * wedp2 << " % " << endl;
cout << "Period 3 : " << (100/8) * wedp3 << " % " << endl;
cout << "Period 4 : " << (100/8) * wedp4 << " % " << endl;
cout << "Thursday Period 1 : " << (100/8) * thup1 << " % " << endl;
cout << "Period 2 : " << (100/8) * thup2 << " % " << endl;
cout << "Period 3 : " << (100/8) * thup3 << " % " << endl;
cout << "Period 4 : " << (100/8) * thup4 << " % " << endl;
cout << "Friday Period 1 : " << (100/8) * frip1 << " % " << endl;
cout << "Period 2 : " << (100/8) * frip2 << " % " << endl;
cout << "Period 3 : " << (100/8) * frip3 << " % " << endl;
cout << "Period 4 : " << (100/8) * frip4 << " % " << endl;
cout << "Saturday Period 1 : " << (100/8) * satp1 << " % " << endl;
cout << "Period 2 : " << (100/8) * satp2 << " % " << endl;
cout << "Period 3 : " << (100/8) * satp3 << " % " << endl;
cout << "Period 4 : " << (100/8) * satp4 << " % " << endl;