| | |
while loop
![]() |
•
•
Join Date: Oct 2006
Posts: 1
Reputation:
Solved Threads: 0
Hi i have this program and have a problem it is a basic program for exponents and now i need to add a while loop so that if the user enters a number greater that 10 it asks them to input a number lower or equal to 10, here is my code can someone help me?.
C Syntax (Toggle Plain Text)
#include <stdio.h> main( ) { /* y */ /* calculate x */ /* */ /* where x and y are integers and y >= 0 */ int base, power; long result = 1; int counter = 0; while ( x <= 10); printf("Enter the base number : "); scanf("%d",&base); printf("Enter the nth power to which base will be raised"); scanf("%d",&power); { for (counter++ < power) result = result * base; } printf("The base of %d raised to",base the %dth power is % ld\n",power,result); return 0; }}}
Last edited by ~s.o.s~; Oct 11th, 2006 at 1:00 pm. Reason: Added code tags, learn to use them yourself
1. Please edit your post to use code tags to preserve spacing and tabs.
2. main() must be declared like this:
I realize neither of the above answer your questions, but fix those and we will look at your post again.
2. main() must be declared like this:
C Syntax (Toggle Plain Text)
int main() { // blabla return 0; }
I realize neither of the above answer your questions, but fix those and we will look at your post again.
•
•
Join Date: Nov 2004
Posts: 15
Reputation:
Solved Threads: 0
x is not declared as a variable anywhere that I can see. this should give a complier error.
Also, your while statement is terminated by a semicolon. This would work for do-while statement but not when the using a while by itself. If using a while in this way it should be followed by braces surrounding the code to be executed during each iteration of the loop.
Also, your while statement is terminated by a semicolon. This would work for do-while statement but not when the using a while by itself. If using a while in this way it should be followed by braces surrounding the code to be executed during each iteration of the loop.
•
•
•
•
Also, your while statement is terminated by a semicolon
I think what you're trying to do is:
C Syntax (Toggle Plain Text)
for (counter = 0; counter < power; counter++) { }
hmmm, int to long conversion....
![]() |
Similar Threads
- Help with gui loop. (C)
- Loop...without the loop (Java)
Other Threads in the C Forum
- Previous Thread: removing double quotes using strpbrk()
- Next Thread: Read Line from serial port buffer
| Thread Tools | Search this Thread |
* ansi array asterisks binarysearch calculate changingto char character cm convert copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createprocess() database feet fflush fgets file floatingpointvalidation fork forloop function givemetehcodez global grade gtkwinlinux hacking histogram homework i/o inches infiniteloop input interest intmain() iso kernel keyboard kilometer km linked linkedlist linux locate looping loopinsideloop. lowest match meter microsoft mqqueue number oddnumber odf open opendocumentformat openwebfoundation owf pattern pdf performance posix power probleminc process program programming pyramidusingturboccodes radix read recv recvblocked research reversing scanf segmentationfault sequential single socket socketprograming socketprogramming standard string suggestions systemcall threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault win32api windowsapi






