1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream> //header containing cout and cin
#include <string>
#include <iomanip>
using namespace std; //introduces namespace std needed to use cout and cin
int main()
{
string DIM,invalid,start,end,DIMtable,UNIT1table,UNIT2table;
double factor,inc,sum=0,convert1,val1,val2;
int dec1,dec2,lines,lastval,count=0,width1,width2,tablength1,tablength2;
bool userinput;
cout << "Enter length, mass or time: ";
cin >> DIM;
do
{
if(DIM == "length" || DIM == "mass" || DIM == "time")
{
cout << "\nEnter the starting value: ";
cin >> val1;
cout << "\nEnter the ending value: ";
cin >> val2;
cout << "\nEnter the increment value: ";
cin >> inc;
cout << "\nEnter the starting value decimal places: ";
cin >> dec1;
cout << "\nEnter the ending value decimal places: ";
cin >> dec2;
}
for(double i=val1; i<=val2; i+=inc)
count++;
if(count < 3 || count > 25)
{
cout << "\n INVALID ENTRY - TOO LITTLE OR TO MANY LINES IN THE TABLE - RESTARTING\n";
cout << "\n ENTER STARTING, ENDING AND INCREMENT VALUES THAT PRODUCE 3 - 25 LINES\n";
userinput = true;
}
else if(val1 < 0 || val2 < 0 || inc < 0 || dec1 < 0 || dec2 < 0)
{
cout << "\n INVALID ENTRY - ALL VALUES MUST BE >= 0 - RESTARTING\n";
userinput = true;
}
else
{
userinput = false;
}
}while(userinput);
cout << "loop has been exited";
return 0;
}
|