ooh cool. I believe it accurately depicts if a number is prime or not! But getch() is now not working to keep the program open long enough to completely read it, nor is syste("pause"), which I don't use... but since getch() isn't working I tried it and it didn't work either.
And I do have everything you put now lol
19 Replies - 1692 Views - Last Post: 27 January 2013 - 11:48 PM
#16
Re: How do I get program to identify prime number?
Posted 27 January 2013 - 02:02 AM
#17
Re: How do I get program to identify prime number?
Posted 27 January 2013 - 02:41 AM
Bawnawgwa, on 27 January 2013 - 02:02 AM, said:
ooh cool. I believe it accurately depicts if a number is prime or not! But getch() is now not working to keep the program open long enough to completely read it, nor is syste("pause"), which I don't use... but since getch() isn't working I tried it and it didn't work either.
And I do have everything you put now lol
And I do have everything you put now lol
Probably so. Add a second getch(); just before the return 0; to get it to keep the window open for you. Another way is to add scanf("%s", garbage); where "garbage" is a small char array that's never used.
The one thing you don't have, is a compiler that was written for Windows. Something is still in the input stream (aka keyboard buffer), and that is allowing the program to "skip" over the first getch(); -- it sees the char in the input stream, takes it and says "Thanks a lot", and scoots on down the road and the console window closes.
Since I use a modern compiler, I don't see that behavior very often. The window stays open when the program is finished, 95% of the time. Happened all the time in Turbo C, however.
Keep your hands off the keys during program execution, unless required.
This post has been edited by Adak: 27 January 2013 - 02:42 AM
#18
Re: How do I get program to identify prime number?
Posted 27 January 2013 - 10:16 AM
Hooray! That second getch() did the trick. Yeah to run c programs I apparently cannot use visual studio... I write c++ in visual studio and then save a .c copy when it is finished... But this one I guess I had to work with it IN c...
Thank you for your help haha I finally finished!
Thank you for your help haha I finally finished!
#19
Re: How do I get program to identify prime number?
Posted 27 January 2013 - 04:01 PM
Cue the fat lady to sing!
"At last... my code compiles along,
My sleepless nights are over,
And my program runs like a song"...
(with apologizes to a great song).
"At last... my code compiles along,
My sleepless nights are over,
And my program runs like a song"...
(with apologizes to a great song).
#20
Re: How do I get program to identify prime number?
Posted 27 January 2013 - 11:48 PM
xtreampb, on 27 January 2013 - 08:29 AM, said:
well mod results in a float most of the time. you are storing a float in an integer. That may lead you in a better direction.
Well, I'm sorry to say this...but on what basis did you say mod results in a float??
what mod does is it returns the remainder of a division and well, remainder can never be a floating point value.
One more thing...the operands mod takes should be int...any other datatype used in a mod operation will give the error as follows.
error: invalid operands to binary %
regards,
Raghav
This post has been edited by raghav.naganathan: 27 January 2013 - 11:50 PM

New Topic/Question
Reply



MultiQuote

|