Hi I'm writing a program with two functions: int getNumberFromUser() that asks user for input and ensures the number is >2 and bool isPrime(int n) that returns true if n is prime. The objective is to find all prime numbers up till a certain number so if the user-chosen number was 11, the program should display 2,3,5,7,11. I'm getting some errors. Can someone help me out?
#include <iostream>
using namespace std;
int getNumberFromUser();
bool isPrime();
int num;
bool prime;
int main()
{
getNumberFromUser();
isPrime();
return 0;
}
int getNumberFromUser()
{
cout << "Please enter a positive integer\n";
cin >> num;
}
after recieving number from user .... where are u using it???? u havnt return it!!! and ur function isPrime(int n) have one parameter so in main type isPrime( getNumberFromUser() );
and in getNumberFromUser() type return num;
Please place your code in [dode][/code] tags. Also please supply (exact) errors if you don't understand what they mean.
In your isPrime function definition after the main function, you have an argument which is not present in your function prototype or the call from main.
@noorali15
Please don't use shortened "words" such as 'r' or 'u'. It's really hard to read.