Can you help me to answer my assignment? I'm have a hard time outputting the excess output stars. Below is the problem. Hope someone will respond. Have a nice day!
Write a witty and interactive program as you output the pattern below?
HOW MANY STARS DO YOU WANT? 5
*
***
*****
Oh, you gave me 4 stars more!
#include <iostream>
using namespace std;
int main()
{
  int stars=0;
  cout<<"HOW MANY STARS DO YOU WANT? ";
  cin>> stars;
  int count=0;
  int n=1;
  do{
  for (int i=0; i<n; ++i){
    cout << "*";
    count++;
  }
  n+=2;
  cout << endl;
  } while (count<stars);
  Â
  if (count>stars)
    cout << "Oh, you gave me "<< count-stars<<" stars more!";
  return 0;
}
Comments
Leave a comment