You can find C++ source code all over the internet and in C++ reference books. The vast majority of programs accept input of some form or another, but not all programs use while loops (some don't use loops of any kind). The following example demonstrates input and while loops:
#include <iostream>
#include <string>
#include <sstream>
#include <time.h>
using namespace std;
void PrintOptions( string options )
{
cout << "Please enter one of ";
unsigned int i=0;
while( i < options.length() )
{
if( i )
{
if( i < options.length() - 1 )
cout << ", ";
else
cout << " or ";
}
cout << "'" << options.at( i++ ) << "'";
}
cout << "." << endl;
}
int PromptChar( string prompt, string options )
{
int result = -1;
while( result num )
{
cout << "Well done! You got it right in " << guess << " guesses.\n" << endl;
guess = 0;
}
else
{
++guess;
cout << "Too " << (i<num?"low":"high") << ". Try again." << endl;
}
}
}
return( 0 );
}
write a c++ program to convert binary number to decimal number by using while statement
A = 5do{statement;A = A + 1;} while (A < 10)
This is not a perfect program, but it will get you started in the right direction. Works for any INTEGER up to "some" power of 2 (decimals kill the program). PROGRAM binary IMPLICIT NONE INTEGER remainder, quotient, n, int_input, answer REAL input, dec_input WRITE(*,*) 'Input a number to convert to binary' READ(*,*) input int_input = input dec_input = input - int_input dec_input = abs(dec_input) quotient = abs(input) DO WHILE (dec_input==0) n = 0 answer = 0 DO WHILE (quotient>1) remainder = mod(quotient,2) quotient = quotient/2 answer = answer+remainder*10.**n n = n+1 END DO IF (input<0) answer = -answer answer = answer + quotient*10.**n WRITE(*,"(a,i31)") 'Your answer in binary is:',answer END DO END PROGRAM binary
<script type = "text/javascript"> var input; var rev = 0; input=window.prompt ("Please enter a 5-digit number to be reversed."); input = input * 1; while (input > 0) { rev *= 10; rev += input % 10; input /= 10; } document.write ("Reversed number: " + rev); </script>
Break statements:-its terminates the current while or for loop and continue the program execution from the statement following the terminated.NOTE:-note that it is wmlscript syntax error to use the break statement outside of while or a for statements.example;Breakstatement:Break;Continue statement:-this statement terminate execution of a block of statementin while or for loop and continues execution of loop with the next iteration.note that the continue statement does not terminate the execution of loop and also is wmlscript syntax error to use the break statement outside of while or a for statements.-> in while loop, it jumps back to the condition.-> in for loop,it jumpsto the update expression.syntax:continuestatement:continue;
Input command is used to enter the values while the program is being executed. this command waits for the user to enter the information and then assigns the values accordingly.
write a c++ program to convert binary number to decimal number by using while statement
Filter is a program that accepts a certain type of data as input, transforms it in some manner, and then outputs the transformed data. while Kidneys, organs with several functions, serve essential regulatory roles in most animals, including vertebrates and some invertebrates.
A "do while....." statement is a looping instruction to a program to repeat a stage in the program while some condition is true - e.g while a variable is negative, or, while one variable is less than another. A "do for ....." statement is a looping instruction to a program to repeat a stage in the program a set number of times - e.g for steps = 1 to 10, or, for steps = 1 to (some variable).
// create an BufferedReader from the standard input stream BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String currentLine = ""; int total = 0; // read prices System.out.print("Please enter a price: "); while (total < 5) { double input = 0; try { input = Double.valueOf(currentLine); ++total; } catch (final NumberFormatException ex) { System.out.println("That price was not formatted correctly."); } System.out.print("Please enter a price: "); } Note that this program does nothing with the input, just accepts it form the user.
A = 5do{statement;A = A + 1;} while (A < 10)
I remember doing this in borland c++ many years ago. The strategy is to write an interrupt handler function that will go out the the character buffer and check to see if a key was pressed. you will need to look up in your borland documentation on what this register would be called. i am too poor to afford a compiler right now. then in your game processing loop you code would look something like: stmts if keypressed then check input buffer for char (process char for the action you want it to do) end if stmts your function "keypressed" would be the one to check the interrupt for this this is also similar to how to handle mouse input. sorry i can't give you more help.
This is not a perfect program, but it will get you started in the right direction. Works for any INTEGER up to "some" power of 2 (decimals kill the program). PROGRAM binary IMPLICIT NONE INTEGER remainder, quotient, n, int_input, answer REAL input, dec_input WRITE(*,*) 'Input a number to convert to binary' READ(*,*) input int_input = input dec_input = input - int_input dec_input = abs(dec_input) quotient = abs(input) DO WHILE (dec_input==0) n = 0 answer = 0 DO WHILE (quotient>1) remainder = mod(quotient,2) quotient = quotient/2 answer = answer+remainder*10.**n n = n+1 END DO IF (input<0) answer = -answer answer = answer + quotient*10.**n WRITE(*,"(a,i31)") 'Your answer in binary is:',answer END DO END PROGRAM binary
<script type = "text/javascript"> var input; var rev = 0; input=window.prompt ("Please enter a 5-digit number to be reversed."); input = input * 1; while (input > 0) { rev *= 10; rev += input % 10; input /= 10; } document.write ("Reversed number: " + rev); </script>
While--wend statement is used to execute a loop until a given condition is true.if the condition is false the loop ends and the program continous to the line following eend.
cls input "enter a name"; a$ b=1 while b <=1 print a$ b = b+1 wend end
Break statements:-its terminates the current while or for loop and continue the program execution from the statement following the terminated.NOTE:-note that it is wmlscript syntax error to use the break statement outside of while or a for statements.example;Breakstatement:Break;Continue statement:-this statement terminate execution of a block of statementin while or for loop and continues execution of loop with the next iteration.note that the continue statement does not terminate the execution of loop and also is wmlscript syntax error to use the break statement outside of while or a for statements.-> in while loop, it jumps back to the condition.-> in for loop,it jumpsto the update expression.syntax:continuestatement:continue;