These are notes for 14 October.
#include <iostream>
using namespace std;
int main()
{
// These two loops do the same thing. The 'for' syntax just
// consolidates the loop controls at the top.
for(int num = 2; num < 1000; num *= 2)
{
cout << num << "\n";
}
// Here is the equivalent 'while' syntax:
int num = 2;
while(num < 1000)
{
cout << num << "\n";
num *= 2;
}
return 0;
}
// nested-loops
#include <iostream>
using namespace std;
int main()
{
for(int i = 2; i < 10; i++)
{
for(int j = 2; j < 30; j++)
{
// cout << i*j << "\n";
if(i*j % 2 == 0)
cout << "*";
else
cout << " ";
}
cout << "\n";
}
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double start, stop, step;
cout << "Enter start: ";
cin >> start;
cout << "Enter stop: ";
cin >> stop;
cout << "Enter step: ";
cin >> step;
// double current = start;
cout << fixed << setprecision(3);
cout << "Miles Kilometers\n";
for(double current = start;
current <= stop;
current += step)
{
cout << setw(10) << current << " ";
cout << setw(10) << current * 1.609 << "\n";
}
return 0;
}