Thread: introduction to c++

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    3

    Smile introduction to c++

    hey everybody,
    please if somebody can answer my simple questions about loops,cstrings,strings,pointers.......thanx
    Last edited by ai_bob; 06-09-2007 at 04:48 PM.

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    Don't ask us such a broad question. Nobody is willing to write a whole tutorial just for you. Either ask a specific question or read tutorials on the internet or your book(s). Simply type 'c++ tutorial' in google.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    3
    yes i know, i read the tutorial on this site....
    this prime or not prime example, is it right? if yes please explain the for loop...

    Code:
    #include <iostream>
    using namespace std;
    void main ()
    {
      int n,i;
      char r;
    do
        {
           cout <<"enter n:";
           cin>>n;
    }
    while(n<0);
    if(n&#37;2==0 && n!=2) 
    cout<<n<<"it's not a prime number"<<endl;
    else
    {
    for(i=3 ; i<=n/2 ; i=i+2)
    if(n%i==0) break;
    if(i>n/2)
    cout<<n<<"is a prime number"<<endl;
    else cout <<n<<"is not a prime number"<<endl;
    }
    do
        cout<<"continue (y/n):";
        cin>>r;
    }
    while(r!='y' && r!='n' && r!='Y' && r!='N')
    }
    while (r=='y' || r=='n');
    }
    Last edited by ai_bob; 06-09-2007 at 04:39 PM.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    903
    void main() is evil. Use int main() instead. If you want to know if the code is right well... compile it. Tell us what you expect it to do and what it does instead and if there is an error message post it here. Also, indent your code.

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    3
    thank you,
    i got today a few books , if i have a question i'll post ....

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Indenting wouldn't kill you either

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Introduction and Thanks in Advance!
    By Gallaton in forum C++ Programming
    Replies: 3
    Last Post: 05-12-2009, 12:37 AM
  2. Good Online Introduction to Memory Management in C?
    By miku05 in forum C Programming
    Replies: 1
    Last Post: 03-26-2007, 08:00 AM
  3. Question about the introduction to pointers lesson
    By Freemind11 in forum C++ Programming
    Replies: 11
    Last Post: 02-15-2006, 11:45 PM
  4. centering text for introduction
    By PHP in forum C++ Programming
    Replies: 8
    Last Post: 12-25-2002, 01:41 PM
  5. Introduction to MFC
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 12-06-2001, 11:35 AM