Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Program keeps on crashing...
Author Message
AsianSensation

Posted: Wed Sep 10, 2003 9:23 pm   Post subject: Program keeps on crashing...

We were suppose to make a simple program that tells if a number is prime or not, but my program keeps on crashing, the windows xp error message keeps on popping up, and I don't know what's wrong, can someone help me? btw, I'm using Dev c++

 code: #include #include int main () {     int num;     cout << "Please input a number between 1 - 1000, inclusive\n";     cin >> num;         for (int i = 0; i < sqrt (num); i++)     {         if (num % i == 0)             {                 cout << "This number is not prime\n";             }     }           cin.ignore (1, '\n');     return 0; }

Mazer

Posted: Wed Sep 10, 2003 9:26 pm   Post subject: (No subject)

i haven't tried to run your program, but my guess is that it's trying to do a modulus by 0.
AsianSensation

Posted: Wed Sep 10, 2003 9:30 pm   Post subject: (No subject)

OMG!!!!

Stupid Stupid Stupid.....

All those math practices.....

and I make this mistake.....

Tony

Posted: Wed Sep 10, 2003 10:04 pm   Post subject: (No subject)

you got this code all wrong... the division check should start with 2 ( cuz remember - prime is divisible by 1 and itself). Though that would be wrong too since 2 itself is a prime number. And would screw up your loop if sqrt(num) <2

I remember posting a really efficient algorithm for finding prime numbers... You should search for that on forum, that might come in handy
Tony's programming blog. DWITE - a programming contest.
AsianSensation

Posted: Thu Sep 11, 2003 5:16 pm   Post subject: (No subject)

yeah, I did that when I fixed the code

lol, I was brain dead or something, recently, I keep finding myself in situations that I shouldn't be in...

for example, in my data management class, I was doing permutations, and I thought P(n, r) was n! / r!... I'm making sooo many simple :newbie: mistakes....
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 5 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: