| | |
Newbie question in C PLEASE help!!!
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 48
Reputation:
Solved Threads: 0
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);
while(i<=num)
{
printf("*");
i++;
}
}
}
any help would be apreciated!!!
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);
while(i<=num)
{
printf("*");
i++;
}
}
}
any help would be apreciated!!!
C Syntax (Toggle Plain Text)
main() { int num, i; while(num>1) <----- {
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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Oct 2008
Posts: 48
Reputation:
Solved Threads: 0
•
•
•
•
Why do you make it so complicated?
You can do with one while!
And please : if you send code put it between CODE-tags
im really sorry, im new to this website,
which CODE tags should i use?
could you please give me a hint with doing it just with while, i tried to do it like you suggested in your first reply but got infinite loop
thanx a lot.,
sorry again
>which CODE tags should i use?
Click here.
Click here.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
•
•
Join Date: Oct 2008
Posts: 15
Reputation:
Solved Threads: 1
you should use this
c Syntax (Toggle Plain Text)
code = c withing brackets;
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......
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......
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Oct 2008
Posts: 48
Reputation:
Solved Threads: 0
•
•
•
•
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......
I have just started CPD Computer Programming course, and its a part from our first assignment,
thanx a lot!!!
cheers!!!
![]() |
Similar Threads
- Newbie Question - How to generate a link (PHP)
- Redirecting - Newbie Question (PHP)
- Basic scripting question (Getting Started and Choosing a Distro)
- HttpContext.Current Question (VB.NET)
- newbie... Java load large picture :) Lit'l help plez (Java)
- Newbie Question - Hiding php extension (PHP)
- Stupid Newbie Question (C)
- AGP Aperture Size Question (Windows NT / 2000 / XP)
- How to network two Win98 machines (Networking Hardware Configuration)
Other Threads in the C Forum
- Previous Thread: Infinite loop problem
- Next Thread: Transfer data to/from the Windows clipboard
Views: 1003 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for C
#include * array arrays asterisks binarysearch calculate changingto char cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv fflush file fork forloop framework functions getlasterror givemetehcodez grade graphics gtkwinlinux hacking hardware histogram homework inches include incrementoperators input iso kernel keyboard km lazy linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue mysql number opendocumentformat opensource overwrite owf pattern pdf performance pointer pointers posix problem probleminc process program programming radix recursion recv research reversing scanf scripting segmentationfault sequential socket socketprograming spoonfeeding standard string structures student systemcall testing threads turboc unix user variable voidmain() wab whythiscodecausesegmentationfault windowsapi






