| | |
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
•
•
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
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez graphics gtkgcurlcompiling gtkwinlinux hardware highest homework i/o ide inches initialization intmain() iso km license linked linkedlist linux linuxsegmentationfault list logical_drives loopinsideloop. lowest match matrix microsoft motherboard mqqueue multi mysql oddnumber odf open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string strings suggestions test testautomation unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi






