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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.