Writing A Program

This is a discussion on Writing A Program within the C++ Programming forums, part of the General Programming Boards category; Well, I am fairly new to C++ but I have written a few small programs. Since I do not know ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    3

    Writing A Program

    Well, I am fairly new to C++ but I have written a few small programs. Since I do not know how to save it so i can see if it works, i guess I am asking how to do it. Because I want to be able to use what i creat, no matter how small. ANd to make sure i did it right.

    SO what do i save it as to be able to use teh program?

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    You want to compile it I assume. How about looking at the tutorials on this site...

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    You can save any C++ program as a simple text file. Most people use .cpp as the extension (and .c for C programs), but I've seen .cxx and .cc files before.

    You'll need to compile the program -- translate it from C++ to the computer's internal language -- by using a compiler. Dev-C++ includes the good MinGW Windows compiler, as well as a beginner-friendly interface; most Unix systems come with a default compiler I think.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    */Death*/,

    Be patient….

    Installing, configuring, and learning to use a compiler/IDE can be tricky. Hopefully, everything will go smoothly, but don’t get too frustrated if it takes you half a day. If you do choose the Dev-C++ compiler, there are some instructions here..

    I have written a few small programs…
    Whenever you install a new compiler, you should always try-out a simple "Hello World" program first.

    In fact, it’s a good idea to start your “real program” as little “Hello World” type program. …Add one or two lines of code, re-compile and test-run. Continue this way ‘till your program is done. One of the most common beginner mistakes is to write the whole program before compiling. You can end-up with so many compiler errors, that you don’t know where to start debugging.

    Expert programmers use the same approach. They write small parts of the program at a time (of course, more than one or two lines ), testing the small parts as they develop the program.

    This technique takes some practice, because you have to add lines to your program in a way that allows the incomplete program to compile, and so that it tells you something when you run it.
    Last edited by DougDbug; 10-06-2006 at 12:28 PM.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Most people use .cpp as the extension (and .c for C programs), but I've seen .cxx and .cc files before.
    I've also heard of .c++ and .C for case insensitive systems.

    To compile a simple Hello World program in Dev-C++:
    1. Launch Dev-C++.
    2. Create a new file (probably CTRL-N).
    3. There should be a default program typed up. You can try it or
      Code:
      #include <iostream>
      
      using namespace std;
      
      int main() {
          cout << "Hello, World!" << endl;
      
          cin.get();
          return 0;
      }
    4. Choose Compile in the Compile menu (CTRL-F9, I think).
    5. Choose Run in the Compile menu (CTRL-F10, I think).

    Dev-C++ also has a compile and run command; I belive it's F9.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing a program to make a calendar
    By Northstar in forum C Programming
    Replies: 17
    Last Post: 11-07-2007, 10:34 AM
  2. writing a calendar program help please!!!
    By Newbie2006 in forum C Programming
    Replies: 7
    Last Post: 11-20-2002, 06:36 PM
  3. Replies: 5
    Last Post: 11-19-2002, 08:36 PM
  4. Help with a file writing program
    By pritesh in forum C Programming
    Replies: 3
    Last Post: 11-11-2001, 12:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21