Thread: Re: [Dev-C++] BloodShed Dev-C++
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Wobien <roo...@pl...> - 2008-04-01 13:58:40
|
Hello Kenneth, On this list we dicuss subject in public, so that everybody can participate. So please if you answer, reply to all, so that everybody recieves it. Also, use plain text without attachments, so copy your code in the mail. I copied your code below, so that everybody can see what we are talking about. Your code compiles fine for me. As it is it does not give any results. There are several mistakes in it: 1. your for loops for i, j.....p start with i=1, j=2, k=3 etc. Why? O can be a digit between 1 and 9, so that is OK, but N can also be a digit between 1 and 9. You are excluding the possibility N=1 without any reason. The same for the others. 2. You compile the value of ONE. That is OK. But than you assign ONE + ONE to the variable TWO. But this way you do'nt know if this is the supposed value of TWO = ( T * 100) + (W * 10) + O I think you have to realise that in the block of code within the parentheses following the big if-statement, (so all your code from here onwards), all the digits O, N, E, T, W...V have a value. You have to check if these values match the requirements mentioned in the header of your program. The first (different digitis for different letters, is checked by the big if- statement. The second ( first digits must not be zero) you can look after by using the right start values in the for statements. the other three you still have to check. So calculate TWO, SEVEN and NINE the same way you calculated ONE, and than check of each of the requirements. For each check, use an if-statement and only execute the rest of the code if the requirement is fullfilled. /****************************************************************************** * Description: Assign in all possible ways a digit to each of the letters * * that occur in the words ONE, TWO, SEVEN and NINE, so that: * * - different digits are assigned to different letters; * * - the digit assigned to the first letter of each word * * is not zero; * * - the equality ONE + ONE = TWO holds; * * - SEVEN is a prime number; * * - NINE is a perfect square. * * * ******************************************************************************/#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <math.h>int main(void) {int O, N, E, T, W, S, V, I;int i, j, k, l, m, n, o, p, x, y;unsigned int ONE, TWO, SEVEN, NINE;unsigned int a, b, c, d, sq_root_of_seven;/* for() loop is being used to randomly assign a digit to each of theletters * * that occur in the words ONE, TWO, SEVEN and NINE. Different letters are* * assigned distinct digits.*/ for (i = 1; i <= 9; i++) { O = i; for (j = 2; j <= 9; j++) { N = j; for (k = 3; k <= 9; k++) { E = k; for (l = 4; l <= 9; l++) { T = l; for (m = 5; m <= 9; m++) { W = m; for (n = 6; n <= 9; n++) { S = n; for (o = 7; o <= 9; o++) { V = o; for (p = 8; p <= 9; p++) { I = p; /* Check to ensure that every letter isnot equal to each other * * then assign into variable ONE, addthe value of ONE to ONE * * then assign it into variable TWO*/ if ((O != N) && (N != E) && (O != E) &&(T != W) && (W != O) && (T != O) && (S != E) && (E != V) && (V != N) &&(S != V) && (S != N) && (E != N) && (N != I) && (I != E) && (N != E) &&(S != T) && (S != W) && (S != O) && (E != T) && (E != W) && (V != T) &&(V != W) && (V != O) && (N != T) && (N != W) && (I != O) && (I != T) &&(I != W) && (I != S) && (I != V)) { ONE = (O * 100) + (N * 10) + E; TWO = ONE + ONE; /* To compute NINE is a perfectsquare with distinct digits. * * The lowest possible value for NINEis 2823, and the square * * root of 2823 is 53.13. To round itdown is equal to 53. * * The highest possible value forNINE is 9897, and the * * square root of 9897 is 99.48. Toround it down is equal to * * 99. The loop will take from thelowest value 53 until the * * highest value 99 then itterminates. From the result break * * each number digit and assign theminto letters N, I, N, E. * * Then compare the digits beingassigned in letters N, I, N, E * * with other digits being assignedin other letters to ensure * * they are not equal to each other.If any letter is equal to * * each other then look for nextiteration, else assign the * * value x * x to NINE and display itas one of the solutions. */ for (x = 53; x <= 99; x++) { a = x * x; N = a / 1000; b = a % 1000; I = b / 100; c = b % 100; N = c / 10; d = c % 10; E = d / 1; if ((N == I) || (I == E) || (N ==E) || (N == O) || (N == T) || (N == W) || (N == S) || (N == V) || (I ==O) || (I == T) || (I == W) || (I == S) || (I == V) || (E == O) || (E ==T) || (E == W) || (E == S) || (E == V)) continue; NINE = x * x; } /* To compute SEVEN is a prime numberwith distinct digits. * * Prime number is a number which canonly be divided by 1 and * * itself. In the for loop, the valueof SEVEN will only be modulus * * by any numbers except 1 and itselfto determine whether SEVEN is * * prime number or not. If theremainder is equal 0 then SEVEN is * * not prime number. If theremainder is not equal to 0 until the * * loop stops then SEVEN is primenumber. */ SEVEN = (S * 10000) + (E * 1000) + (V* 100) + (E * 10) + N; bool is_prime = true; sq_root_of_seven = sqrt(SEVEN); for (y = 2; y <= sq_root_of_seven;y++) if (SEVEN % y == 0) { is_prime = false; break; } if (is_prime) printf("one = %d, two = %d, seven= %d and nine = %d is a solution.\n", ONE, TWO, SEVEN, NINE); } } } } } } } } } system("PAUSE"); return EXIT_SUCCESS;}----- Original Message -----From: Kenneth ChungTo: WobienSent: Tuesday, April 01, 2008 11:44 AMSubject: RE: [Dev-C++] BloodShed Dev-C++Hi Wobien,Please find the attached file this program actually generated the mentionederror message upon compiling. If I try to comment out the specified linewhich complained by the compiler then it is able to compile. However, Ifind that the solutions don't look quite correct. Kindly to check my sourcecode whether my idea and program structure is on the right track. As I amnot a very experience programmer and new to C language. Appreciate yourhelp.regards,Kenneth> From: roo...@pl...> To: ken...@ho...; dev...@li...> Subject: Re: [Dev-C++] BloodShed Dev-C++> Date: Mon, 31 Mar 2008 14:10:50 +0200>> Hi Kenneth,> bool is a build-in datatype in C++, not in C. If you #include <stdbool.h>> you should be able to use it in C without problems.> '# recursion too deep' is not about an unrecognised datatype, but aboutthe> structure of your program.> Without seeing the program it is impossible to tell you what is wrong with> it,> so please copy the program into your mail.>> Wobien>> ----- Original Message -----> From: Kenneth Chung> To: dev...@li...> Sent: Monday, March 31, 2008 3:15 AM> Subject: [Dev-C++] BloodShed Dev-C++>>> Hi All,>> Currently I am using the BloodShed Dev-C++ version 4.01. When I includethe> #include <stdbool.h> and wish to use bool data type in my program howeverit> doesn't work. When I compile The error message shows '# recursion toodeep'> something like that.>> Kindly advise. Urgent!>> regards,> Kenneth>>> Click here Search for local singles online @ Lavalife.>>>> Click here Search for local singles online @ Lavalife.>>>> -------------------------------------------------------------------------> Check out the new SourceForge.net Marketplace.> It's the best place to buy or sell services for> just about anything Open Source.>http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace>>>> _______________________________________________> Dev-cpp-users mailing list> Dev...@li...> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users>Click here Fashion, beauty, health, relationship advice and horoscopes. |