![]() |
|
#1
|
|||
|
|||
making table of LCM using arraysI am trying to make a table of LCM values using an array. I know that to find the LCM , you need the GCM. Im stuck in my program. Is it possible to call a function in a function? This is what I have so far. The table is set to 10 x 10. I currently have user input because it waits for the user to enter the row number and the column number for that specific LCM value. I.E 2x6, LCM is 6. Its currently got 4 errors, and im stuck and unsure hwo to fix them. Can someone help?
Code:
|
|
#2
|
||||
|
||||
Re: making table of LCM using arraysHi azn,
Welcome to the GIDForums™. First, dont confuse with parameters and return values. For example, you have declared the findLCM statement like this: CPP / C++ / C Code:
Rather, the return value is double! So, change that to CPP / C++ / C Code:
Also, you have to declare the data array as double, since you are returning a double value. Next, the error which comes here is this: 'r' : undeclared identifier in line 31 So, whats the error? Because the compiler doesnt know where the variable r has been declared. You have to declare it as int r, because of the scope problems. Then, you have to define your functions findLCM, and gcd outside the main function. The next error is in this line: CPP / C++ / C Code:
It should be like this: CPP / C++ / C Code:
Again, in this function: CPP / C++ / C Code:
Now that all the syntax errors are gone, here comes the logical error: Division by zero!!! That is because you are passing 0 and 0 as the values to gcd function in the loop: CPP / C++ / C Code:
Last but not the least, you have to define the main function as int main(), rather that void main. And you should return 0 to indicate successful execution: CPP / C++ / C Code:
Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#3
|
|||
|
|||
Re: making table of LCM using arraysHello Paramesh.
Thank You for taking the time to take a look at my program. I've managed with your help to fix up all the errors from it. But one thing that confuses me is , some things that you suggested didint work. Is it because I am using visual basics? Here is a copy of my code that works for me at least . [edit] ohhhhh i just noticed theres a visual basics c++ section!! CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: making table of LCM using arraysI still need some help. My program has logical errors. For example wjen i enter 2 abd 3, the LCM is 6, but it shows the number before it. Cany someon help ?
|
|
#5
|
||||
|
||||
Re: making table of LCM using arraysQuote:
Quote:
Quote:
As for the code you just posted, it wouldn't compile. When I fixed the error it seemed to run perfectly for 10 by 10, although I didn't check all 100 answers. If there's a problem, you'll have to be more specific. Show us the error, don't just tell us about it. [edit]Oh, I see. When you enter 4 rows and 5 columns you get rows 1-3 and colums 1-4. Your description wasn't clear at all. The answer has to do with loops. With that clue you should be able to find the problem.[/edit] __________________
Age is unimportant -- except in cheese |
|
#6
|
||||
|
||||
Re: making table of LCM using arraysQuote:
Here we go: For more simplification, remove all doubles in your code and convert them to int. Did you read this: Quote:
CPP / C++ / C Code:
Again, when printing: CPP / C++ / C Code:
Similarly, vary c from 1 to colcount. At last: Quote:
Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
Recent GIDBlog
Meeting the populace by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Making a whole column in table lowercase... | geedubya15 | MySQL / PHP Forum | 1 | 02-Jun-2005 11:50 |
| Hash Table & Graph | Kay Chan | C++ Forum | 7 | 08-Oct-2004 07:44 |
| Help making a survey in C++ | elavalos | C++ Forum | 2 | 23-Sep-2003 16:40 |
| [Tutorial] MySQL Basics | nniehoff | MySQL / PHP Forum | 15 | 23-Mar-2003 19:42 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The