Consider the following example 10. N The program is used to input data. If at the time the program starts n input 10, but because of errors, including input 100 then still have to input data 100. There are other ways to this, where using a loop that is not known with certainty the amount, but it is known when the loop is done, that while there is more data. So the program is modified into a sample number 11.
Example 10:
# include <iostream>
# include <conio.h>
main () {
int b, number;
court <<"Enter the number of data ="; cin>> b;
for (int i = 1; i <= b; i + +)
{court <<"data to" <<i <<"="; cin>> number;}
getch ();
}
Example 11:
# include <iostream>
# include <conio.h>
main () {
int number;
char there;
court <<"Are there any data you input (Y / N) ="; cin>> exists;
while (there == 'Y')
{court <<"\ nData ="; cin>> number;
court <<"Are there any data you input (Y / N) ="; cin>> exists;
}
getch ();}
Example 10:
# include <iostream>
# include <conio.h>
main () {
int b, number;
court <<"Enter the number of data ="; cin>> b;
for (int i = 1; i <= b; i + +)
{court <<"data to" <<i <<"="; cin>> number;}
getch ();
}
Example 11:
# include <iostream>
# include <conio.h>
main () {
int number;
char there;
court <<"Are there any data you input (Y / N) ="; cin>> exists;
while (there == 'Y')
{court <<"\ nData ="; cin>> number;
court <<"Are there any data you input (Y / N) ="; cin>> exists;
}
getch ();}
No comments:
Post a Comment