Author |
Topic: My hobby (Read 2494 times) |
|
hanzack
Forum Senior Member
lalala...I'm singing a song of arimaa.
Gender:
Posts: 35
|
I want a program to plot all leap years from 1800 to 2007, and add an indentation everytime it plot 10 leap years. like this----> 1804 1808 1812 1816 1820 1824 1828 1832 1836 1840 1844 1848 1852 1856 1860 1864 1868 1872 1876 1880 1884 1888 1892 1896 1904 1908 1912 1916 1920 1924 1928 1932 1936 1940 1944 1948 1952 1956 1960 1964 1968 1972 1976 1980 1984 1988 1992 1996 2000 2004 I wrote like this---> #include <stdio.h> int main() { int x; for(x = 1800; x <= 2007; x++){ if(x % 4 == 0){ if(x % 100 == 0){ if(x % 400 == 0){ printf("%d ", x); if((x - 1800) % 10 == 0){ printf("\n");}else{} }else{} }else{ printf("%d ", x); if((x - 1800) % 10 == 0){ printf("\n");}else{} }else{}} return 0; } I'm not sure that's like it, because I don't know how to use linux? centos?. Please help me~~ This is not my homework, so no need to hold back
|
|
IP Logged |
|
|
|
FireBorn
Forum Guru
Arimaa player #1832
Gender:
Posts: 123
|
|
Re: My hobby
« Reply #1 on: Jun 19th, 2010, 10:08am » |
Quote Modify
|
By indentation, do you mean new line? Also, you can use [ code ] tags to make it format correctly (the # button). Get rid of the "else {}" things. They are unnecessary. What output are you getting right now?
|
|
IP Logged |
|
|
|
hanzack
Forum Senior Member
lalala...I'm singing a song of arimaa.
Gender:
Posts: 35
|
|
Re: My hobby
« Reply #2 on: Jun 19th, 2010, 3:58pm » |
Quote Modify
|
yes i meant new lines. I didn't know the expression. and I can't use linux at home so I don't know what output I get I want to use both windows xp and linux on my computer but don't know how to do it. and once I download linux, I'm afraid I may not be able to use windows xp anymore
|
|
IP Logged |
|
|
|
FireBorn
Forum Guru
Arimaa player #1832
Gender:
Posts: 123
|
|
Re: My hobby
« Reply #3 on: Jun 19th, 2010, 4:16pm » |
Quote Modify
|
There are C++ compilers for Windows. I believe Visual Studio Express is free. http://www.thefreecountry.com/compilers/cpp.shtml I think in order to use linux and windows dualboot you'll have to reformat the drive first. Unless you have another one, maybe. I'm not sure of the details either.
|
|
IP Logged |
|
|
|
hanzack
Forum Senior Member
lalala...I'm singing a song of arimaa.
Gender:
Posts: 35
|
|
Re: My hobby
« Reply #4 on: Jun 19th, 2010, 10:15pm » |
Quote Modify
|
Thank you FireBorn! I got this---> 1804 1808 1812 1816 1820 1824 1828 1832 1836 1840 1844 1848 1852 1856 1860 1864 1868 1872 1876 1880 1884 1888 1892 1896 1904 1908 1912 1916 1920 1924 1928 1932 1936 1940 1944 1948 1952 1956 1960 1964 1968 1972 1976 1980 1984 1988 1992 1996 2000 2004 How come please tell me how to make a new line evrytime it plots 10 leap years
|
« Last Edit: Jun 19th, 2010, 10:26pm by hanzack » |
IP Logged |
|
|
|
Oystein
Forum Full Member
Arimaa player #3272
Gender:
Posts: 21
|
|
Re: My hobby
« Reply #5 on: Jun 20th, 2010, 2:46am » |
Quote Modify
|
Make a counter for the number of years that has been plotted. Then use this counter instead of the year to check if you should add a new line.
|
|
IP Logged |
|
|
|
hanzack
Forum Senior Member
lalala...I'm singing a song of arimaa.
Gender:
Posts: 35
|
|
Re: My hobby
« Reply #6 on: Jun 20th, 2010, 8:37pm » |
Quote Modify
|
I wrote like this---> #include <stdio.h> int main() { int x, y = 0; for(x = 1800; x <= 2007; x++){ if(x % 4 == 0 && ((x % 100) != 0 || x % 400 == 0)) printf("%d ", x);y++; if(y % 10 == 0){ printf("\n");}} return 0; } and got this---> 1804 1808 1812 1816 1820 1824 1828 1832 1836 1840 1844 1848 1852 1856 1860 1864 1868 1872 1876 1880 1884 1888 1892 1896 1904 1908 1912 1916 1920 1924 1928 1932 1936 1940 1944 1948 1952 1956 1960 1964 1968 1972 1976 1980 1984 1988 1992 1996 2000 2004 My pc hates me! help meee! awawawa
|
|
IP Logged |
|
|
|
hanzack
Forum Senior Member
lalala...I'm singing a song of arimaa.
Gender:
Posts: 35
|
|
Re: My hobby
« Reply #7 on: Jun 20th, 2010, 9:01pm » |
Quote Modify
|
Thank you very much! I made it!
|
|
IP Logged |
|
|
|
knarl
Forum Guru
Arimaa player #1648
Gender:
Posts: 104
|
|
Re: My hobby
« Reply #8 on: Jun 20th, 2010, 9:37pm » |
Quote Modify
|
The problem is you were printing a new line after every leap year where a multiple of 10 years had elapsed since 1800, and as correctly mentioned earlier in this thread, you could index the number of leap years with a separate variable. Here's some reformatted, corrected code: #include <stdio.h> int main() { int x,leap=0; for(x = 1800; x <= 2007; x++) { if((x%4 == 0) && ((x%100 != 0)||(x%400 == 0))) { leap++; if(leap%10 == 0) { printf("%d \n", x); } else { printf("%d ", x); } } } return 0; }
|
|
IP Logged |
|
|
|
knarl
Forum Guru
Arimaa player #1648
Gender:
Posts: 104
|
|
Re: My hobby
« Reply #9 on: Jun 20th, 2010, 9:46pm » |
Quote Modify
|
By the way. I use a nice free C/C++ development environment for windows (cross platform) called dev C++ by bloodshed http://www.bloodshed.net/ It's licence is GNU. Cheers, knarl.
|
|
IP Logged |
|
|
|
Polyfractal
Forum Senior Member
Arimaa player #3241
Gender:
Posts: 27
|
|
Re: My hobby
« Reply #10 on: Jun 21st, 2010, 6:10am » |
Quote Modify
|
I believe Visual Studio Express is free too, if you want to use a Microsoft product.
|
|
IP Logged |
|
|
|
hanzack
Forum Senior Member
lalala...I'm singing a song of arimaa.
Gender:
Posts: 35
|
|
Re: My hobby
« Reply #11 on: Jun 22nd, 2010, 12:04am » |
Quote Modify
|
Thank you very much knarl Polyfractal!!! The information is ultra hyper helpful to me. I'm very happy ,so I have no choice but dance! ♪♪ヽ(ω・ヽ)(ノ・ω)&# 65417;♪♪
|
|
IP Logged |
|
|
|
Arimabuff
Forum Guru
Arimaa player #2764
Gender:
Posts: 589
|
|
Re: My hobby
« Reply #12 on: Jun 22nd, 2010, 7:40am » |
Quote Modify
|
on Jun 22nd, 2010, 12:04am, hanzack wrote:Thank you very much knarl Polyfractal!!! The information is ultra hyper helpful to me. I'm very happy ,so I have no choice but dance! ♪♪ヽ(ω・ヽ)(ノ・ω)&# 65417;♪♪ |
| I think that's Japanese for "I don't have that font".
|
|
IP Logged |
|
|
|
|