Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Program keeps on crashing...
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
AsianSensation




PostPosted: 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 <iostream.h>
#include <math.h>

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;
}
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: 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




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

OMG!!!!

Stupid Stupid Stupid.....

All those math practices.....

and I make this mistake.....

Very Shocked
Doh!
Cussing
Hit Wall
Tony




PostPosted: 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 Smile
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
AsianSensation




PostPosted: 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:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: