Está en la página 1de 8

Event-Controlled Looping

#include <iostream>
#include <string>
#include <windows.h>
using namespace std;

int main()
{ int x;
char ans;
do{
for(x=0;x<=5;x++)
{
cout<<x;
Sleep(1000);
}
cout<<\nTry again (y/n)?";
cin>>ans;
system("cls");

}while(ans=='y'|| ans=='Y');
system("pause>0");
}



Screen Output:

012345
Try again () y/n?
#include <iostream>
#include <windows.h>

using namespace std;
int main( )
{
int nR=5,nE,nI = 1, nC = 0;
for (nE = 1; nE <= nR; nE++)
{ nC += nI;
nI += 2;
}
cout<<nC;
system("pause>0");
}


Screen Output:

25

Event-controlled with String
Functions


#include <iostream>
#include <windows.h>
using namespace std;
void ERIC(int x, int y);
int main()
{
system("color C");
ERIC(40,10);cout<<"MAPUA";
system("pause>0");
}
void ERIC(int x, int y)
{
HANDLE eric;
COORD bogs;
bogs.X = x;
bogs.Y = y;
eric = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(eric,bogs);
}

MAPUA
Screen Output:

WANTED BOARDERS: ROOM 4 RENT
How many boarders? 2
Enter the Boarder's name: Elias
Enter the Boarder's name: Pinaglabanan

Nakopya na po sa database.



/* check for input failure in case the drive is
not accessible if true display a message
that the input file is not accessible return
the integer 1 from the main program */
if (!outName)
{
cout << "Di pupwede!\n";
return 1;
}
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <windows.h>
using namespace std;

int main()
{
ifstream inName;
string name, searchName;
double price;
bool found = false;
// open the input file
inName.open("Boarders.txt");

if (!inName)
{
cout << "File not Found!\n";
system("pause");
return 1;
}


cout << setprecision(2) << fixed
<< showpoint;
cout << "Enter name to search: ";
getline(cin, searchName);
do {
/* read in the name on the file until SPACE is reached */
getline(inName, name, ' ');
if (name==searchName)
found = true;
inName >> price;
inName.ignore();
} while (!found && !inName.eof());
if (found)
cout << "\nThe Boarding Fee for "
<< searchName << " costs " << price <<
endl;
else
cout << "\nThe Boarding Fee for " <<
searchName << " was not found\n";
inName.close();
system("pause>0"); }

Screen Output1:

File not Found!
Press any key to continue . . .



Note:

Screen Output1 will display if no
file is found on the drive path
Screen Output2:

Enter name to search: eric

The Boarding Fee for eric
costs 45.50

Note:

Screen Output2 will display if
file is found on the drive path

También podría gustarte