User Input Help!

Below I have my code, where it checks if a number is prime, and then it overloads the -- and ++ operators to find the previous prime number and the post prime number. Right now my code works perfectly if you set the value to check, but I want the user to be able to input the value themselves, and this is where I'm running into issues. I thought of adding these following lines to my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//I would add this to the class
public:
  void set_prime(int new_prime);

//I would write this function
 void PrimeNumber::set_prime_num (int new_prime) {
      num = new_prime;
 }

//I would call it like this in main
int user_num;
cout << "Enter your number: "
cin >> user_num;
prime1.set_prime_num(user_num);


But none of this is working. Here is my code without trying to do user input

Last edited on
closed account (j3Rz8vqX)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//I would add this to the class
public:
  void set_prime(int new_prime);

//I would write this function
 void PrimeNumber::set_prime (int new_prime) {//<-----Method name wasn't coherent, FIXED
      num = new_prime;
 }

//I would call it like this in main
int user_num;
cout << "Enter your number: "
cin >> user_num;
prime1.set_prime(user_num);//<----Edit: fix to be coherent. 

Possible spoiler: (May not necessarily solve your problem)
http://pastie.org/8684077#13-15,36,44,59,62-66

Have fun.
Last edited on
thank you!!
Topic archived. No new replies allowed.