You are on page 1of 7

// This program illustrates the use of logical operators

// Abdirazak Khader Yousuf 1001852498

/*

1. getting the library ready

2. declaration of variables

3. prompting the user to input the starting value

4. storing the starting value

5. prompting the user to enter the end value

6. storing the end value

7. prompting the user to enter the type of conversion

8. storing it

9. repeating step 7 and 8

10. using if statement and including it the for loop and doing the math inside the loop

11. using if else statement to do the other type of conversion

12. doing the math inside the else statment.

*/

#include <iostream>

#include<fstream> // step1

#include<iomanip>

using namespace std;

int main()

double startTemp, endvalue, stepSize;

char tempType1, tempType2;


double inches, centimetres; // step 2

cout << " please enter the starting value:"; // step 3

cin >> startTemp; // step4

cout << " enter the maximum value (end value) :" ; // step5

cin>> endvalue; // ste[p 6

cout << " enter step size: "; // step 7

cin >> stepSize; // step 8

cout << " enter i or I for inches to centimeters conversion: " ; // step 9

cin>> tempType1;

cout << " enter C or c for centimeteres to inches conversion: " << endl;

cin >> tempType2; // step 9

cout << " table generated by Abdirazak Khader yousuf and ID no is 1001852498 " << endl;

if (tempType1 == 'i' || tempType1 == 'I'){

for (int x=0 ; x<= endvalue; x+= stepSize) {

cout << fixed << showpoint << setprecision(2); // step 10

centimetres = startTemp*2.54 ;

cout << startTemp << " I" << setw(8) << centimetres << endl;
startTemp+=stepSize ;

}}

else if (tempType2 == 'c' || tempType2 == 'C') {

for (int x= startTemp; x<=endvalue ; x+= stepSize){ // step 11

cout << fixed << showpoint << setprecision(2); // step 12

inches= (startTemp/2.54);

cout << startTemp << setw(8) << inches << endl;

startTemp+=stepSize;

} else { cout << " wrong key pressed. the program has terminated " } ;

return 0;

}
SAMPLE 1

SAMPLE 2
SAMPLE 3
SAMPLE 4

SAMPLE 5

You might also like