Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

can someone help me fix this program, when i run this it never outputs the answer and when i input y it ends the program

can someone help me fix this program, when i run this it never outputs the answer and when i input y it ends the program

output:

Please enter a number to simplify: 72 6 SqRt [2]

Do you have another number to simplify? y for yes or n for no y

Please enter a number to simplify: 36 6

Do you have another number to simplify? y for yes or n for no y

Please enter a number to simplify: 29 SqRt [29]

Do you have another number to simplify? y for yes or n for no

code:

#include

using namespace std;

int checkprime(int n){ int flag = 0; int m = n / 2; for(int i = 2; i <= m; i++){ if(n % i == 0){ flag = 1; break; } } if (flag==0) return 1; return 0; }

int main(){ char ans = 'y'; int n = 0; bool b = false; while(ans == 'y'){ cout << "Please enter a number to simplify:" << endl; cin >> n; int isPrime = checkprime(n); if(isPrime){ cout << "SqRt[" << n << "]" <> ans; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How to Choose the Sample Size

Answered: 1 week ago