I can’t seem to figure out why there is no input asked when an invalid number is asked for. The code I have so far is below: int main() { cout… | Cheap Nursing Papers

I can’t seem to figure out why there is no input asked when an invalid number is asked for. The code I have so far is below: int main() { cout…

I can’t seem to figure out why there is no input asked when an invalid number is asked for. The code I have so far is below:

int main()

{

 cout << “Please enter your numbers: “; // Output to user

 string st;  // Initialize Variable

 cin >> st;// Input numbers

 stringstream stream(st); // String stream

 int arr[50]; // Max array

 int count = 0; // Initialize variable

 int number;

 while (stream >> number)  // While loop

 {

  arr[count] = number;  // Array

  count++;     // Increment count

  if (stream.peek() == ‘,’) 

   stream.ignore();  // Checks for comma and ignores them

 }

  for (int i = 0; i < count; i++) // For Loop

  {

  number = arr[i];   // Number into array

  {

   if ((number %3 == 0) && (number %5 == 0)) // Checks if the number is divisible by 3 or 5

   {

    cout << “Number: ” << number << ” – FizzBuzz” << endl; // Output ” – FizzBuzz” if divisible by 3 or 5

   }

   else if (number % 3 == 0) // Checks if the number is divisible by 3

   {

    cout << “Number: ” << number << ” – Fizz” << endl; // Output ” – Fizz” if divisible by 3

   }

   else if (number % 5 == 0) // Checks if the number is divisible by 5

   {

    cout << “Number: ” << number << ” – Buzz” << endl; // Output ” – Buzz” if divisible by 5

   }

   else

   {

    cout << number << ” is NOT divisible by either 3 or 5.” << endl; // Output if number not divisible by 5

    cout << “Please enter another number: “; // Output asking for another number

    cin >> number;  // Input for new number

    break;

   }

  }

 }

 return 0;

}

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now

Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp