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
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main()
{
int number;
char Answer;
cout << "this program is to check if the number is prime or not... Do you want to start? (Y/N)";
cin >> Answer;
if (Answer == 'Y')
{
cout <<"Enter an integer:";
cin>> number;
for(int i=2; i < number; i++)
{
if (number%i==0)
cout << "number is not prime" << endl;
elseif(number%i!=0)
cout << "number is prime" << endl;
return 0;
}
}
elseif (Answer == 'N')
cout << "as you wish.. Have a nice day"<<endl;
else
cout << "please insert a valid choice"<<endl;
cout << "do you want to try again?";
do
{
cout <<"Enter an integer:";
cin>> number;
for(int i=2; i < number; i++)
{
if (number%i==0)
cout << "number is not prime" << endl;
elseif(number%i!=0)
cout << "number is prime" << endl;
return 0;
}
}while (Answer == 'Y');
}
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.
@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..