hey everybody,
please if somebody can answer my simple questions about loops,cstrings,strings,pointers.......thanx
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.
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.
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%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.
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.
thank you,
i got today a few books , if i have a question i'll post ....
Indenting wouldn't kill you either