answersLogoWhite

0

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 );

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

How is the INPUT statement different from the LET statement in?

The INPUT statement is used to prompt the user for data entry during program execution, allowing for interactive input. In contrast, the LET statement is used to assign a value to a variable directly within the program's code without user interaction. While INPUT gathers data from the user, LET simply assigns predefined values or calculations to variables. This distinction makes INPUT essential for interactive applications, whereas LET is fundamental for setting and manipulating variable values programmatically.


What is the difference between input and Read data statement?

The INPUT statement in programming is used to read data from user input during the execution of a program, allowing for dynamic data entry. In contrast, the READ statement typically retrieves pre-defined data from a specified source, such as a file or data structure, and is often used in conjunction with data storage formats. Essentially, INPUT is interactive, while READ is more about accessing existing data.


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


Write a program that will graph using for loop?

A = 5do{statement;A = A + 1;} while (A < 10)


Conversion of decimal to binary in fortran?

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&gt;1) remainder = mod(quotient,2) quotient = quotient/2 answer = answer+remainder*10.**n n = n+1 END DO IF (input&lt;0) answer = -answer answer = answer + quotient*10.**n WRITE(*,"(a,i31)") 'Your answer in binary is:',answer END DO END PROGRAM binary

Related Questions

What is the use of INPUT statement?

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.


How is the INPUT statement different from the LET statement in?

The INPUT statement is used to prompt the user for data entry during program execution, allowing for interactive input. In contrast, the LET statement is used to assign a value to a variable directly within the program's code without user interaction. While INPUT gathers data from the user, LET simply assigns predefined values or calculations to variables. This distinction makes INPUT essential for interactive applications, whereas LET is fundamental for setting and manipulating variable values programmatically.


What is the difference between input and Read data statement?

The INPUT statement in programming is used to read data from user input during the execution of a program, allowing for dynamic data entry. In contrast, the READ statement typically retrieves pre-defined data from a specified source, such as a file or data structure, and is often used in conjunction with data storage formats. Essentially, INPUT is interactive, while READ is more about accessing existing data.


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


How are kidneys filters?

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.


How do you write a java program that prompts the user for a list of 5 prices?

// 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 &lt; 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.


What is the difference between Do While statements and Do For statements?

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).


Write a program that will graph using for loop?

A = 5do{statement;A = A + 1;} while (A < 10)


In language Borland C How do you make a computer program accept input without stopping it with a specific input statement For example: Asteroids game-program runs but accepts arrow keys while running?

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.


Which statement concerning osmosis and active transport is NOT correct?

The statement that osmosis requires energy input from the cell is not correct. Osmosis is a passive process that does not require energy input from the cell, while active transport does require energy to move molecules against their concentration gradient.


Conversion of decimal to binary in fortran?

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&gt;1) remainder = mod(quotient,2) quotient = quotient/2 answer = answer+remainder*10.**n n = n+1 END DO IF (input&lt;0) answer = -answer answer = answer + quotient*10.**n WRITE(*,"(a,i31)") 'Your answer in binary is:',answer END DO END PROGRAM binary


Java script program to Print the Fibonacci series using array?

&lt;script type = "text/javascript"&gt; var input; var rev = 0; input=window.prompt ("Please enter a 5-digit number to be reversed."); input = input * 1; while (input &gt; 0) { rev *= 10; rev += input % 10; input /= 10; } document.write ("Reversed number: " + rev); &lt;/script&gt;