![]() |
|
#1
|
|||
|
|||
TableI am trying to creat a program that will allow me to intialise the values 2 through 1000 in a table, set all their values to 1, then from there run a program that will find, which value is a first number (only dividable by its self and 1) im assuming using the % with no rest would find these values, and when these numbers are found in the table, change their value to 0, continue to the next number, eliminate its mulptiples, continue untill only first numbers remain, and then the program should display these numbers in a table. How would i go about doing this. My first problem is my program wont even cout my table with values from 1-1000, it goes from 706 to 1001.....
CPP / C++ / C Code:
any ideas, helps tricks? |
|
#2
|
||||
|
||||
Re: TableNot a clue what you are trying to do except
Quote:
CPP / C++ / C Code:
__________________
Age is unimportant -- except in cheese |
|
#3
|
|||
|
|||
Re: TableQuote:
You declare an array that has 1000 elements. Index values for the elements go from zero to 999, not zero to 1000. There are several violations of the C++ standard that will not allow the program to compile in my compiler (GNU g++). I have made it comply with Standard C++ as follows: CPP / C++ / C Code:
Now, I didn't fix your bug: you must not use an index value of 1000 since the array only has elements from 0 through 999. Also, if you want to initialize the array to have values of all 1, you must use a loop. There is no way (no way) that a declaration statement can initialize array elements to anything other than zero other than giving a list of values. You can't use an assignment statement to give values to multiple array elements. Regards, Dave |
|
#4
|
|||
|
|||
Re: Tablelets say i set em all to 0, then want to creat a program that will pick out first numbers, and change their value to 1, then at the end of the program, display the table with only values of still 1 to show, 0 being not first numbers, such as 4,6,8,9, etc. Basicly, i need the program to find every number thats a multitple of another, and elimante it.)? how would i do this?
|
|
#5
|
|||
|
|||
Re: TableQuote:
In C or C++ you can use the modulus operator '%' to determine whether one integer is an exact multiple of another. For integer data types x and y, with y not equal to zero, then the value of the expression x%y is equal to zero if and only if x is an exact multiple of y. That is the same as saying y is a factor of x if and only if the value of x%y is equal to zero. CPP / C++ / C Code:
Regards, Dave |
|
#6
|
|||
|
|||
Re: TableCPP / C++ / C Code:
what i got just to date, gives me the values from 706 to 1000, giving every value in my table 0, and at the end of execution, i get a microsoft error, program must be shut down, blah blah. I use iostream.h and void main, cause if not, ms visual c++ bitches at me. |
|
#7
|
|||
|
|||
Re: TableQuote:
I hate to repeat myself, but when you declare an array like int Tableau[1000] it is only legal to use index values from 0 to 999, not 0 to 1000. Change your main() to: CPP / C++ / C Code:
Now, it will print values of Tableau[0] up to and including Tableau[999]. Note that if are using a command window with default properties, it probably only has a buffer length 0f 300, which means that Tableau[0] through Tableau[705] have scrolled off of the screen. If you want to see all of the values, then you can either 1. Redirect standard output to a file and look at the file in a text editor. or 2. Increase the screen buffer (layout in the "Properties" dialog box) to something more than 1000 Regards, Dave P.S. If you use the following as your main file, all standard C++ compilers will be happy: CPP / C++ / C Code:
Maybe you don't care about other compilers or other people's opinions, but if you ever get out from under Microsoft Visual C++, you may find that certain programming habits will not serve you well. I'm just trying to help. The program that I show above works just fine with Microsoft Visual C++ version 6.0 as well as other C++ compilers to which I have access (Borland, GNU, Microsoft Visual C++ 2005, GNU). Free advice, freely given (and just my opinion): Take it or leave it. D. |
|
#8
|
|||
|
|||
Re: Tableok, so now that i have that problem fixed, how can i get the program to find first numbers, and change the value of the said number in my table to 1, since they all have a starting value of 0. And dave i do appretiate ur help, im just a noob trying to learn, so please resist the urge to punch me
|
|
#9
|
|||
|
|||
Re: TableQuote:
I didn't mean to sound harsh, but I guess it did, and I apologize. I mean well, but sometimes it just comes out wrong. I really want to see you have success and to feel that you can ask anything, any time. No one was born knowing this stuff (knowing programming languages or knowing how to help people either), and I am still learning. People usually have to tell me things three times before it soaks in, so if I only told you the same thing twice, you are one up on me. I'll try to be more patient, as I ask others to be patient with me. Regards, Dave |
|
#10
|
|||
|
|||
Re: Tablehaha, no worries man, where all noobs at some point! still not having any sucess with my math problem tho, it keeps setting all the numbers in my table to 1, so i guess the condition is always met,thus a problem in my code :S
|
Recent GIDBlog
Observations of Iraq by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Cannot create a table in DB | WaltP | MySQL / PHP Forum | 3 | 26-Apr-2006 16:09 |
| making table of LCM using arrays | azncrazycooler | C++ Forum | 5 | 01-Dec-2005 03:52 |
| Sorting a table to give each user a rank | Wowl | MySQL / PHP Forum | 1 | 23-Apr-2005 14:45 |
| C league table | Networkedd | C Programming Language | 3 | 13-Mar-2005 17:20 |
| [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