question 6.17 Deitel & Deitel...
the twelve days of christmas song. Write an application that uses repitition and if structures to print the song "the twelve days of christmas". After spending a couple of days trying different techniques
(from my limited repertoire) the code i came up with was...
which works using a double subscripted array and looping through the first subscript, however, it doesnt fullfill the requirements, it still works with the if statement but i know thats not right using the same condition as in the for loop. in my search on this board i found the 2003 xmas song competition and had a look at the various efforts (some really bizarre code), however the competition did not have the same requirements as this question and i could not find any other person who had asked about this problem from this board (i hate saying that because i know someone will now say, oh yeah, i just spent 2 minutes searching and i found this....) but i didnt, Breezer's efforts amazed me even if i didnt fully understand what was going on. And something really wierd happenned when i annotated his codeCode:using System; class Class1 { // main entry point for the application static void Main(string[] args) { string[,] stringArray = { {"this"}, {"is"}, {"a test"}, {"to see"}, {"how i can"}, {"impliment"}, {"repetition"}, {"and if structures"}, {"to print"}, {"this text"}}; for(int loop=0; loop<stringArray.Length; loop++) { //if (stringArray.Length>0) Console.WriteLine(stringArray[loop, 0]); } } }
as i could not understand why he was assigning e to a and not just output e, when i ran the the program the output consisted of digits and not text as had been before and even after changing the code back to original the same effect happenned, tried every version of compiling, even closing dot net down and restarting still produced the same effect of just digits, i must be missing soemthing obviouslyCode:// 12Scramble.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <string> #include <cmath> using namespace std; int main(int argc, char* argv[]) { char a; int b = 0; int c = 0; int e; string d = "11110010011101100000010000101110000101101010011000000100011001101001011001001110110011100010111000000100001001101000011010011110000001001111011001100110000001001100011000010110010011101001011011001110001011101011011010000110110011100000010010110110100111100000010000101110010011101010111010100110000001000011011011110110011011101010011000000100110011101010011001110110001011100000010000101110111101100000010010110110101001100101000010000010000001000000111010000110010011100010111001001110100101100010011011100110101001100000010010010110011101100000010010000110000001000000111010100110100001100100111000000100001011100100111010100110101001100111010001010000010100001111001001110110000001000010111000010110101001100000010011001110101001101100011011110110011101100010011000000100001001101000011010011110000001001111011001100110000001001100011000010110010011101001011011001110001011101011011010000110110011100000010010110110100111100000010000101110010011101010111010100110000001000011011011110110011011101010011000000100110011" "10101001100111011000101110000001000010111011110110000001001011011010100110010100000010101011101110111101100000010000101110101011100100111000101110001101101010011000000100001001101111011001101110101001101100111000000100100001100111011000100110010100001000001000000100000011101000011001001110001011100100111010010110001001101110011010100110000001001001011001110110000001001000011000000100000011101010011010000110010011100000010000101110010011101010011010100110011101000101000001010000111100100111011000000100001011100001011010100110000001000010111000010110100101100100111000100110000001000010011010000110100111100000010011110110011001100000010011000110000101100100111010010110110011100010111010110110100001101100111000000100101101101001111000000100001011100100111010101110101001100000010000110110111101100110111010100110000001001100111010100110011101100010111000000100001011101111011000000100101101101010011001010000001010100001011001001110101001101010011000000100011001100100111010100110011101101100011000010110000001000001" "01101010011001110110110011100101000000101010111011101111011000000100001011101010111001001110001011100011011010100110000001000010011011110110011011101010011011001110000001001000011001110110001001100101000010000010000001000000111010000110010011100010111001001110100101100010011011100110101001100000010010010110011101100000010010000110000001000000111010100110100001100100111000000100001011100100111010100110101001100111010001010000010100001111001001110110000001000010111000010110101001100000010001100110111101101010111001001110001011100001011000000100001001101000011010011110000001001111011001100110000001001100011000010110010011101001011011001110001011101011011010000110110011100000010010110110100111100000010000101110010011101010111010100110000001000011011011110110011011101010011000000100110011101010011001110110001011100000010000101110111101100000010010110110101001100101000001100010111101101010111001001110000001001100011011110110001101100011011010011110000001000100011010010110010011100010011011001110010100000010101000" "01011001001110101001101010011000000100011001100100111010100110011101101100011000010110000001000001011010100110011101101100111001010000001010101110111011110110000001000010111010101110010011100010111000110110101001100000010000100110111101100110111010100110110011100000010010000110011101100010011001010000100000100000010000001110100001100100111000101110010011101001011000100110111001101010011000000100100101100111011000000100100001100000010000001110101001101000011001001110000001000010111001001110101001101010011001110100010100000101000011110010011101100000010000101110000101101010011000000100011001101001011001100110001011100001011000000100001001101000011010011110000001001111011001100110000001001100011000010110010011101001011011001110001011101011011010000110110011100000010010110110100111100000010000101110010011101010111010100110000001000011011011110110011011101010011000000100110011101010011001110110001011100000010000101110111101100000010010110110101001100101000001100010100101100110111010100110000001001110011011110110" "00110110001001100000010001001110100101100111011011100110110011100101000001100010111101101010111001001110000001001100011011110110001101100011011010011110000001000100011010010110010011100010011011001110010100000010101000010110010011101010011010100110000001000110011001001110101001100111011011000110000101100000010000010110101001100111011011001110010100000010101011101110111101100000010000101110101011100100111000101110001101101010011000000100001001101111011001101110101001101100111000000100100001100111011000100110010100001000001000000100000011101000011001001110001011100100111010010110001001101110011010100110000001001001011001110110000001001000011000000100000011101010011010000110010011100000010000101110010011101010011010100110011101000101000001010000111100100111011000000100001011100001011010100110000001001100111010010110000111100010111000010110000001000010011010000110100111100000010011110110011001100000010011000110000101100100111010010110110011100010111010110110100001101100111000000100101101101001111000000100001011" "10010011101010111010100110000001000011011011110110011011101010011000000100110011101010011001110110001011100000010000101110111101100000010010110110101001100101000011001010100101100001111000000100111001101010011010100110110011101010011000000100001101101000011010011110100101100111011011100110010100000110001010010110011011101010011000000100111001101111011000110110001001100000010001001110100101100111011011100110110011100101000001100010111101101010111001001110000001001100011011110110001101100011011010011110000001000100011010010110010011100010011011001110010100000010101000010110010011101010011010100110000001000110011001001110101001100111011011000110000101100000010000010110101001100111011011001110010100000010101011101110111101100000010000101110101011100100111000101110001101101010011000000100001001101111011001101110101001101100111000000100100001100111011000100110010100001000001000000100000011101000011001001110001011100100111010010110001001101110011010100110000001001001011001110110000001001000011000000100000011101010" "01101000011001001110001011100100111010100110101001100111010001010000010100001111001001110110000001000010111000010110101001100000010011001110101001100110111010100110011101100010111000010110000001000010011010000110100111100000010011110110011001100000010011000110000101100100111010010110110011100010111010110110100001101100111000000100101101101001111000000100001011100100111010101110101001100000010000110110111101100110111010100110000001001100111010100110011101100010111000000100001011101111011000000100101101101010011001010000110010101010011001101110101001100111011000000100110011101110111010000110011101101100111000000100110011101110111010010110101101101011011010010110011101101110011001010000110010101001011000011110000001001110011010100110101001101100111010100110000001000011011010000110100111101001011001110110111001100101000001100010100101100110111010100110000001001110011011110110001101100010011000000100010011101001011001110110111001101100111001010000011000101111011010101110010011100000010011000110111101100011011000" "11011010011110000001000100011010010110010011100010011011001110010100000010101000010110010011101010011010100110000001000110011001001110101001100111011011000110000101100000010000010110101001100111011011001110010100000010101011101110111101100000010000101110101011100100111000101110001101101010011000000100001001101111011001101110101001101100111000000100100001100111011000100110010100001000001000000100000011101000011001001110001011100100111010010110001001101110011010100110000001001001011001110110000001001000011000000100000011101010011010000110010011100000010000101110010011101010011010100110011101000101000001010000111100100111011000000100001011100001011010100110000001001010011010010110111001100010111000010110000001000010011010000110100111100000010011110110011001100000010011000110000101100100111010010110110011100010111010110110100001101100111000000100101101101001111000000100001011100100111010101110101001100000010000110110111101100110111010100110000001001100111010100110011101100010111000000100001011101111011000000100" "10110110101001100101000010100010100101101110011000010110001011100000010010110110100001101001011000100110110011100000010010110110100101100011011011010110100101100111011011100110010100001100101010100110011011101010011001110110000001001100111011101110100001100111011011001110000001001100111011101110100101101011011010110110100101100111011011100110010100001100101010010110000111100000010011100110101001101010011011001110101001100000010000110110100001101001111010010110011101101110011001010000011000101001011001101110101001100000010011100110111101100011011000100110000001000100111010010110011101101110011011001110010100000110001011110110101011100100111000000100110001101111011000110110001101101001111000000100010001101001011001001110001001101100111001010000001010100001011001001110101001101010011000000100011001100100111010100110011101101100011000010110000001000001011010100110011101101100111001010000001010101110111011110110000001000010111010101110010011100010111000110110101001100000010000100110111101100110111010100110110011" "10000001001000011001110110001001100101000010000010000001000000111010000110010011100010111001001110100101100010011011100110101001100000010010010110011101100000010010000110000001000000111010100110100001100100111000000100001011100100111010100110101001100111010001010000010100001111001001110110000001000010111000010110101001100000010001110110100101100111011000101110000101100000010000100110100001101001111000000100111101100110011000000100110001100001011001001110100101101100111000101110101101101000011011001110000001001011011010011110000001000010111001001110101011101010011000000100001101101111011001101110101001100000010011001110101001100111011000101110000001000010111011110110000001001011011010100110010100000111001010010110011101101010011000000100001001100100111010101110101101101011011010100110010011101100111000000100001001100100111010101110101101101011011010010110011101101110011001010000101000101001011011100110000101100010111000000100101101101000011010010110001001101100111000000100101101101001011000110110110101101001" "01100111011011100110010100001100101010100110011011101010011001110110000001001100111011101110100001100111011011001110000001001100111011101110100101101011011010110110100101100111011011100110010100001100101010010110000111100000010011100110101001101010011011001110101001100000010000110110100001101001111010010110011101101110011001010000011000101001011001101110101001100000010011100110111101100011011000100110000001000100111010010110011101101110011011001110010100000110001011110110101011100100111000000100110001101111011000110110001101101001111000000100010001101001011001001110001001101100111001010000001010100001011001001110101001101010011000000100011001100100111010100110011101101100011000010110000001000001011010100110011101101100111001010000001010101110111011110110000001000010111010101110010011100010111000110110101001100000010000100110111101100110111010100110110011100000010010000110011101100010011001010000100000100000010000001110100001100100111000101110010011101001011000100110111001101010011000000100100101100111011000" "00010010000110000001000000111010100110100001100100111000000100001011100100111010100110101001100111010001010000010100001111001001110110000001000010111000010110101001100000010000101110101001100111011000101110000101100000010000100110100001101001111000000100111101100110011000000100110001100001011001001110100101101100111000101110101101101000011011001110000001001011011010011110000001000010111001001110101011101010011000000100001101101111011001101110101001100000010011001110101001100111011000101110000001000010111011110110000001001011011010100110010100000010101010100110011101100000010000001110100101100000111010100110010011101100111000000100000011101001011000001110100101100111011011100110010100000111001010010110011101101010011000000100001001100100111010101110101101101011011010100110010011101100111000000100001001100100111010101110101101101011011010010110011101101110011001010000101000101001011011100110000101100010111000000100101101101000011010010110001001101100111000000100101101101001011000110110110101101001011001110110" "11100110010100001100101010100110011011101010011001110110000001001100111011101110100001100111011011001110000001001100111011101110100101101011011010110110100101100111011011100110010100001100101010010110000111100000010011100110101001101010011011001110101001100000010000110110100001101001111010010110011101101110011001010000011000101001011001101110101001100000010011100110111101100011011000100110000001000100111010010110011101101110011011001110010100000110001011110110101011100100111000000100110001101111011000110110001101101001111000000100010001101001011001001110001001101100111001010000001010100001011001001110101001101010011000000100011001100100111010100110011101101100011000010110000001000001011010100110011101101100111001010000001010101110111011110110000001000010111010101110010011100010111000110110101001100000010000100110111101100110111010100110110011100000010010000110011101100010011001010000100000100000010000001110100001100100111000101110010011101001011000100110111001101010011000000100100101100111011000000100100001" "10000001000000111010100110100001100100111000000100001011100100111010100110101001100111010001010000010100001111001001110110000001000010111000010110101001100000010010100110001101101010011001101110101001100111011000101110000101100000010000100110100001101001111000000100111101100110011000000100110001100001011001001110100101101100111000101110101101101000011011001110000001001011011010011110000001000010111001001110101011101010011000000100001101101111011001101110101001100000010011001110101001100111011000101110000001000010111011110110000001001011011010100110010100001010001000110110101001100110111010100110011101100000010000110110100001100010011010010110101001101100111000000100001001101000011001110110110001101001011001110110111001100101000000101010101001100111011000000100000011101001011000001110101001100100111011001110000001000000111010010110000011101001011001110110111001100101000001110010100101100111011010100110000001000010011001001110101011101011011010110110101001100100111011001110000001000010011001001110101011101011" "01101011011010010110011101101110011001010000101000101001011011100110000101100010111000000100101101101000011010010110001001101100111000000100101101101001011000110110110101101001011001110110111001101110011001010000110010101001011000011110000001001110011010100110101001101100111010100110000001000011011010000110100111101001011001110110111001100101000001100010100101100110111010100110000001001110011011110110001101100010011000000100010011101001011001110110111001101100111001010000011000101111011010101110010011100000010011000110111101100011011000110110100111100000010001000110100101100100111000100110110011100101000000101010000101100100111010100110101001100000010001100110010011101010011001110110110001100001011000000100000101101010011001110110110011100101000000101010111011101111011000000100001011101010111001001110001011100011011010100110000001000010011011110110011011101010011011001110000001001000011001110110001001100101000010000010000001000000111010000110010011100010111001001110100101100010011011100110101001100000010010" "01011001110110000001001000011000000100000011101010011010000110010011100000010000101110010011101010011010100110011101000101000001010000111100100111011000000100001011100001011010100110000001000010111011101110101001100011011000101110000101100000010000100110100001101001111000000100111101100110011000000100110001100001011001001110100101101100111000101110101101101000011011001110000001001011011010011110000001000010111001001110101011101010011000000100001101101111011001101110101001100000010011001110101001100111011000101110000001000010111011110110000001001011011010100110010100000010101011101110101001100011011001101110101001100000010000110110111101100100111000100110110011100000010000110110101001101000011000001110100101100111011011100110010100001010001000110110101001100110111010100110011101100000010000110110100001100010011010010110101001101100111000000100001001101000011001110110110001101001011001110110111001100101000000101010101001100111011000000100000011101001011000001110101001100100111011001110000001000000111010010110" "00001110100101100111011011100110010100000111001010010110011101101010011000000100001001100100111010101110101101101011011010100110010011101100111000000100001001100100111010101110101101101011011010010110011101101110011001010000101000101001011011100110000101100010111000000100101101101000011010010110001001101100111000000100101101101001011000110110110101101001011001110110111001100101000011001010101001100110111010100110011101100000010011001110111011101000011001110110110011100000010011001110111011101001011010110110101101101001011001110110111001100101000011001010100101100001111000000100111001101010011010100110110011101010011000000100001101101000011010011110100101100111011011100110010100000110001010010110011011101010011000000100111001101111011000110110001001100000010001001110100101100111011011100110110011100101000001100010111101101010111001001110000001001100011011110110001101100011011010011110000001000100011010010110010011100010011011001110010100000010101000010110010011101010011010100110000001000110011001001110101001" "100111011011000110000101100000010000010110101001100111011011001110010100000010101011101110111101100000010000101110101011100100111000101110001101101010011000000100001001101111011001101110101001101100111000000100100001100111011000100110010100001000001000000100000011101000011001001110001011100100111010010110001001101110011010100110000001001001011001110110000001001000011000000100000011101010011010000110010011100000010000101110010011101010011010100110011101000101000001010000"; while(c < d.size()) { e = 0; for(b = 0; b < 8; ++b) { if(d[c++] == '1') e += pow(2.0, b); } //a = e; cout << e; } return 0; }
Luigi
ps..sorry for the widescreen effect bit i dont know how to change that and still have the code section work