Question: Hi can someone help me my code. its not working correctly when I enter a number such as 1 5 its suppose to come out

Hi can someone help me my code. its not working correctly when I enter a number such as 15 its suppose to come out 1 through 15 across the 1st row the 16 through 28 on the second and so on to give an hourglass shape with zeros on the empty spaces. like on the example and its coming out wrong, nowhere near it. but I cannot use array, vectors or private functions. please help and look at the sample output. thank you.
my code;
#include
#include
using namespace std;
void printHourglass(int size){
int width = size *2-1;
int mid = size;
for (int i =1; i = size; ++i){
for (int j =1; j = width; ++j){
if (j >= mid - i +1 && j = mid + i -1)
cout i;
else
cout "0";
}
cout endl;
}
for (int i = size -1; i >=1; --i){
for (int j =1; j = width; ++j){
if (j >= mid - i +1 && j = mid + i -1)
cout i;
else
cout "0";
}
cout endl;
}
}
int main(){
char choice;
do {
int size;
cout "Enter size: ";
cin >> size;
printHourglass(size);
cout "More (y/n)?";
cin >> choice;
} while (choice =='y'|| choice =='Y');
return 0;
}
Hi can someone help me my code. its not working

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!