Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: If the user gives an even number (an invalid input), I want the program asks for the input again without running it one more

Question: If the user gives an even number (an invalid input), I want the program asks for the input again without running it one more time. Would you kindly help me to fix it?

An example of the output should look like this:

please enter number of rows (odd nummber): 4 please enter number of rows (odd nummber): 7 * *** ***** ******* ***** *** *

Programming c++:

#include

int main() {

int rows, i, j, k;

printf("please enter number of rows (odd nummber):");

scanf("%d", &rows);

// Ensure that the number of rows entered is odd

if (rows % 2 == 0) {

printf("please enter number of rows (odd nummber): ");

return 0;

}

// Print upper half of diamond

for (i = 1; i <= rows; i += 2) {

// Print spaces

for (j = 1; j <= (rows - i) / 2; j++) {

printf(" ");

}

// Print asterisks

for (k = 1; k <= i; k++) {

printf("*");

}

printf(" ");

}

// Print lower half of diamond

for (i = rows - 2; i >= 1; i -= 2) {

// Print spaces

for (j = 1; j <= (rows - i) / 2; j++) {

printf(" ");

}

// Print asterisks

for (k = 1; k <= i; k++) {

printf("*");

}

printf(" ");

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

What is your boards committee structure? Is it effective?

Answered: 1 week ago