Answer to Question #180922 in C++ for Precious

Question #180922

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!


1
Expert's answer
2021-04-13T03:51:46-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS