Topic List | Page List: 1 |
---|---|
Topic | Can anyone help me with this c++ program? |
Yellow 10/14/18 1:27:15 AM #5: | first off, you're using "while" incorrectly in main. You should be using "if" instead if (n >= 0) 'While' is meant to loop code and will repeat as long as the condition is met. 'if' will only go through once, which is what you're going for here I imagine. If you want to loop through every number up until 12, you would have to use a 'for' loop in your main function. int main() { int n; cout << "Calculate every number up until: "; cin >> n; for (int i = 0; i < n; i++) { if (Prime(i) == 0) cout << i << " is a prime number.\n"; else cout << i << " is not a prime number.\n"; } return 0; } Also, a little tip, to do line ends you can type \n in the middle of the string. That makes the output much easier to read. You can also use endl http://www.cplusplus.com/forum/beginner/2138/ ... Copied to Clipboard! |
Topic List | Page List: 1 |