Hello, Im taking C in school, and i have a problem with my code, nothing happens at all when i run the program.
The task is:
A program is required that prompts the user for a number. The program will then print a series of asterisks to represent the number. If the user enters a number less than 1, the program stops. For example: Enter a number: 5
*****
Enter a number: 3
***
Enter a number: 9
*********
Enter a number: 0
i have decided to use while loop since its a pretest loop
here it is
#include<stdio.h>
main()
{
int num, i;
while(num>1)
{
printf("Enter a number:");
scanf("%d", &num);
What do you think the value of num is where I put the arrow?
Most likely it will be zero but you can never be certain about that.
Put your scanf function before this while, that way you give num a value.
Code tags :
Select your code.
Then click one of the buttons on top of the field where your typing or pasting text.
Hover over all of them to get their meaning. You need the #-button.
Code algorithm :
Get num
While num not=0 print *
Decrement num ----> this is essential otherwise you will never get out of the while loop! And you will loop forever and ever and ever and......
Code tags :
Select your code.
Then click one of the buttons on top of the field where your typing or pasting text.
Hover over all of them to get their meaning. You need the #-button.
Code algorithm :
Get num
While num not=0 print *
Decrement num ----> this is essential otherwise you will never get out of the while loop! And you will loop forever and ever and ever and......
Wow, Thank you sooo much, it works great!!
I have just started CPD Computer Programming course, and its a part from our first assignment,
thanx a lot!!!
cheers!!!
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.