When I run this C++ program that asks the user to enter the population of 4...

60.1K

Verified Solution

Question

Programming

When I run this C++ program that asks the user to enter thepopulation of 4 cities and produce the bar graph

- it runs but ends with a Debug Error - run time check failure 2stack around variable population was corrupted - any help would beappreciated

#include

using namespace std;

int main()

{

int population[4],k;

   int i=1,n=5;

  

   do

   {

       cout<<\"Enter thepopulation of city \"<

    

      cin>>population[i];

       if(population[i]<0)

       cout<<\"populationcannot be negative,Reenter\n\";

       else

       i++;

     }   while (i

    

      cout<<\"\n\n\t\tPOPULATION\n\t   (each * = 1000people)\n\";

       for(int i=1;i

   {

       cout<<\"\nCity\"<

       k=population[i]/1000;

       for(int j=0;j

      cout<<\"*\";

   }

   return 0;

}

Answer & Explanation Solved by verified expert
3.6 Ratings (365 Votes)
Program code tocopyinclude    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students