| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| Evil_Intentions Expert Cheater
 
  Reputation: 65 
 Joined: 07 Jan 2010
 Posts: 214
 
 
 | 
			
				|  Posted: Wed Jun 02, 2010 10:49 pm    Post subject: First little C++ Program |   |  
				| 
 |  
				| Here is a Fibonacci sequence generator that i made. It will create a perfectly accurate sequence no matter the length. 
 http://www.mediafire.com/?rzqnzynzm4u
 
 Unzip the folder and run the program. it will ask how long of a sequence you wish to make. I don't recommend going over a million, it may take a while, but 10k should only take around 30 seconds are so. After the program is finished, a .rtf file will be created in the same folder as the program, you can open it to view your sequence.
 
 I need testers, because I'm not sure if it is working right, so i used a different compiler.
 
 Please report any errors.
 
 Also, this is only my 3rd or so c++ program, i just started last week, so constructive criticism is always good
   
 SOURCE:
 
  	  | Code: |  	  | #include <NTL/ZZ.h> #include <fstream>
 NTL_CLIENT
 
 
 
 int main()
 {
 
 system("cls");
 ZZ count;
 ZZ first;
 ZZ second;
 ZZ third;
 
 ofstream myfile;
 myfile.open("Fib_Sequencce.rtf");
 
 
 system("title Fibonacci");
 system("color 4");
 cout << "Please insert how many iterations you want: ";
 cin >> count;
 
 first=0;
 second=1;
 third=0;
 
 system("cls");
 cout << "Working...Please do not close the window.";
 myfile  << first << "\n" << second << "\n";
 
 
 
 
 while (count >0)
 {
 third=first + second;
 first=second;
 second=third;
 
 myfile << fixed << third << "\n";
 count=count-1;
 
 }
 system("cls");
 cout << "Finished!, please check the folder for your file.\n\n";
 cin.get();
 return 0;
 
 }
 
 | 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| nwongfeiying Grandmaster Cheater
 
 ![]() Reputation: 2 
 Joined: 25 Jun 2007
 Posts: 695
 
 
 | 
			
				|  Posted: Thu Jun 03, 2010 1:48 am    Post subject: |   |  
				| 
 |  
				| Expect a "system"-usage speech from one of the senior programmers. |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Flyte Peanuts!!!!
 
  Reputation: 6 
 Joined: 19 Apr 2006
 Posts: 1887
 Location: Canada
 
 | 
			
				|  Posted: Thu Jun 03, 2010 2:18 am    Post subject: |   |  
				| 
 |  
				|  	  | nwongfeiying wrote: |  	  | Expect a "system"-usage speech from one of the senior programmers. | 
 
 Blah blah blah.
 
 TL;DR - Don't use system. Ever. I will gouge your eyes out.
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Evil_Intentions Expert Cheater
 
  Reputation: 65 
 Joined: 07 Jan 2010
 Posts: 214
 
 
 | 
			
				|  Posted: Thu Jun 03, 2010 2:49 am    Post subject: |   |  
				| 
 |  
				|  	  | Flyte wrote: |  	  |  	  | nwongfeiying wrote: |  	  | Expect a "system"-usage speech from one of the senior programmers. | 
 
 Blah blah blah.
 
 TL;DR - Don't use system. Ever. I will gouge your eyes out.
 | 
 
 GAH...i sorry, i just started a few days ago.... is there something like, "cout.clear()" or anything similar?
 
 And what is so bad about using "system" anyway? Some of the best c++ books use it.
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Flyte Peanuts!!!!
 
  Reputation: 6 
 Joined: 19 Apr 2006
 Posts: 1887
 Location: Canada
 
 | 
			
				|  Posted: Thu Jun 03, 2010 3:22 am    Post subject: |   |  
				| 
 |  
				|  	  | Evil Intentions wrote: |  	  | GAH...i sorry, i just started a few days ago.... is there something like, "cout.clear()" or anything similar? 
 And what is so bad about using "system" anyway? Some of the best c++ books use it.
 | 
 
 There is no need to apologize. It's a common mistake for people learning.
 
 'system()' calls are bad like 'goto' is bad. It promotes bad programming practices. If a C++ book uses it chances are it's crap.
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Evil_Intentions Expert Cheater
 
  Reputation: 65 
 Joined: 07 Jan 2010
 Posts: 214
 
 
 | 
			
				|  Posted: Thu Jun 03, 2010 4:51 am    Post subject: |   |  
				| 
 |  
				|  	  | Flyte wrote: |  	  |  	  | Evil Intentions wrote: |  	  | GAH...i sorry, i just started a few days ago.... is there something like, "cout.clear()" or anything similar? 
 And what is so bad about using "system" anyway? Some of the best c++ books use it.
 | 
 
 There is no need to apologize. It's a common mistake for people learning.
 
 'system()' calls are bad like 'goto' is bad. It promotes bad programming practices. If a C++ book uses it chances are it's crap.
 | 
 
 O.o then you RREEEALLYYY don't want to see my FIRST program. lots of gotos and system calls ^^
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Stylo Grandmaster Cheater Supreme
 
 ![]() Reputation: 3 
 Joined: 16 May 2007
 Posts: 1073
 Location: Israel
 
 | 
			
				|  Posted: Thu Jun 03, 2010 4:57 am    Post subject: |   |  
				| 
 |  
				| Then u should try avoiding that command this isn't c programming it's more batch
 _________________
 
 Stylo |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| NoMercy Master Cheater
 
 ![]() Reputation: 1 
 Joined: 09 Feb 2009
 Posts: 289
 
 
 | 
			
				|  Posted: Fri Jun 04, 2010 9:01 am    Post subject: |   |  
				| 
 |  
				| you should use 
 GetChar();
 
 Btw, if ur book use goto statements, its a little bit old
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Evil_Intentions Expert Cheater
 
  Reputation: 65 
 Joined: 07 Jan 2010
 Posts: 214
 
 
 | 
			
				|  Posted: Fri Jun 04, 2010 3:46 pm    Post subject: |   |  
				| 
 |  
				|  	  | NoMercy wrote: |  	  | you should use 
 GetChar();
 
 Btw, if ur book use goto statements, its a little bit old
 | 
 
 Let me rephrase, the book i use has system calls in the beginning chapter. it introduces other ways later. I just havn't read enough.
 
 and no the book doesn't use goto at all, its just something i remembered from by vbscript and batch days.
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		|  |