Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want to write a program that create an integer i and then enter a value from 1

ID: 3629673 • Letter: I

Question

I want to write a program that create an integer i and then enter a value from 1 to 10. We will calculate the square of their value.

If entered value out of the range, then to ask user enter a value from 1 to 10 until the number is correct

when complete caluculation, ask if the user wishes to start the process again. if not terminate the program (like press x to continue or y to end)

Thank you very much !


Please help me check is there any problems:

#include<stdio.h>
#include<stdlib.h>


int main()
{
int i;
char j='y';


{
do{
printf("Please enter a value between 0 to 10:");
scanf('%d',&i);

if (i<0 || i>10)
{
printf("You have entered wrong number");
printf("Please enter a value between 0 to 10:");
}

else
printf(" The square of your integer %d is %d",i,i*i);


printf(" Do you wish to try another number? (y/n) ");
j=getch();
}while( j == 'y' );
}
printf(" Goodbye! ");


return 0;
}




Explanation / Answer

please rate - thanks

#include<stdio.h>
#include<stdlib.h>

int main()
{
int i;
char j='y';


{
do{
printf("Please enter a value between 0 to 10:");
scanf("%d",&i);

while (i<0 || i>10)
{
printf("You have entered wrong number ");
printf("Please enter a value between 0 to 10: ");
scanf("%d",&i);

}

printf(" The square of your integer %d is %d",i,i*i);


printf(" Do you wish to try another number? (y/n) ");
j=getch();
printf(" ");

}while( j == 'y' );
}
printf(" Goodbye! ");


return 0;
}



Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote