| Omar Elsayed (6) | |||
ok so there is a question that tells me to make user chooses whether he wants to try a program or not... and that program is to see whether the number he inserted is prime or not... that part is easy... but then it said..... after that luck up the user in a loop till he/she enters the right response as Y for yes and N for no. thats the hard part and here is the code but nothing happened
| |||
|
Last edited on
|
|||
| MikeyBoy (175) | |
| Please could you enclose your code in code tags? That will make it much more readable, which means that people will be more likely to take the time to help you. Use the "<>" button to the right of the edit window to do this. | |
|
|
|
| TheIdeasMan (1564) | ||
|
Firstly - my omnipresent request for code tags - the <> button on the right. Have a look at this code I did to help someone else:
It shows an easy way to quit out of a loop. Hope all goes well. | ||
|
|
||
| Jackson Marie (456) | ||||||
|
I've looked quickly your source. Here's my remark : 1-
If I enter 'y' or 'n', then what do you think? You should add two comparisons to fit the checking input. It should look like :
2-
You should not copy a similar code unless you know what you have to do. This makes your code longer and harder to read. 3- Capital letters. 4-
It seems redundant. Look at this :
Your loop will be ended automatically & immediately after the program has finished its prime checking. Then what do you think about 'loop' ?? | ||||||
|
Last edited on
|
||||||
| Omar Elsayed (6) | |
| @Jackson Marie... well the problem is... I can't do the loop.... quiet confusing... and thank you for your remarks...... and thank you all for help.. I really appreciate it.. | |
|
|
|
| TheIdeasMan (1564) | ||
@Omar
How did you get on with the code I gave you in the link? Also, you do not have to test whether all the numbers give a remainder - you only have to go as high as sqrt(n). You also need to make use of functions - the code you have from lines 8 to 30 is basically repeated on lines 32 to 54. At the start, the question to start is rather irrelevant. The use of the return statements causes the program to exit early. Hope this all helps, looking forward to seeing your new code. :) | ||
|
|
||