-
Question Please ????
Hi there....
I have a problem with one of my programs ...and here is the question
" The program is to input five numbers between 1 and 30 such that it gives the output of each number as the corresponding number of asterisks"
the problem is that when I run the program it make me enter the number 2 times then to show the corresponding asterisks......so please any one answer me
Thank You
-
-
download it .....
The Code.txt
-
hey......did you find it ?????
-
Code:
#include <stdio.h>
int main()
{
int counter =1;
int x;
printf( " Enter numbers between 1 to 30 \n " );
while( counter <= 5 ){
printf( "\nEnter the number\n " );
scanf( " %d " ,&x );
while( x <= 30 ){
x = x - 1;
printf( "*" );
if( x == 0 )
{
break;
}
}
counter = counter + 1;
}
printf( " \nThe End\n\n " );
return 0;
}
-
first, can you write a code to print the amount of * equal to a number the user inputs?
-
Code:
scanf( " %d " ,&x );
Check it..
-
I already did it in the code shown......
in the loop >>>>>> while( x <= 30 )....it will do successive subtraction from the number the put * to each 1 subtracted until the number is zero it came out of this loop and increase the counter and so on.....
-
@ rob90
what do you mean by checking it .....
I know that something must be done before something but I don't get it !!!!!
-
Since you still dont get it I'll tell you, you put an extra space in the scanf() function, change it with Moreover you can simplify you program by doing something like:
Code:
scanf("%d", &x);
for(j=0;j<x;j++) putchar('*');
.... // continue the loop
You dont need to make any subtraction
-
IT REALLY WORKS :D:D:D:D:D
really thank you for your help...."Grazie mille"...
Thanks
-
This is the problem:
Code:
scanf( " %d " ,&x );
Take the spaces out of the quotes.