setw-demo.cpp
// setw-demo.cpp
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << setfill('.') << left << setw(10) << "Alice"
<< setfill('0') << right << setw(6) << 15 << endl;
cout << setfill('.') << left << setw(10) << "Bob"
<< setfill('0') << right << setw(6) << 7 << endl;
cout << setfill('.') << left << setw(10) << "Carol"
<< setfill('0') << right << setw(6) << 215 << endl;
cout << setfill('.') << left << setw(10) << "David"
<< setfill('0') << right << setw(6) << 6 << endl;
return 0;
}
while-demo.cpp
#include <iostream>
using namespace std;
int main()
{
int n = 0;
while(n < 10)
{
n++; // OR n+=1 OR n=n+1
cout << n << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
cout << "Enter number (1-5): ";
int num;
cin >> num;
while(num < 1 || num > 5)
{
cout << "ERROR: try again (1-5): ";
cin >> num;
}
cout << "Continuing with " << num << endl;
return 0;
}