Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

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;

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question