0% found this document useful (0 votes)
10 views

Caringal - CODE

Uploaded by

Marvin Cinco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Caringal - CODE

Uploaded by

Marvin Cinco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

Create a program that will produce this output:


=====Temperature Conversion=====
A. Celsius to Fahrenheit
B. Fahrenheit to Celsius
Enter choice: A
Enter temperature in Celsius: 37
In Fahrenheit that is: 98.6
Enter choice: B
Enter temperature in Fahrenheit: 98.6
In Celsius that is: 37
Invalid choice!!!

#include<iostream>
using namespace std;
int main(){
char choice;
double celcius, fahrenheit;
bool ans = false;
do{
cout<<"=====Temperature Conversion====="<<endl;
cout<<"A. Celsius to Fahrenheit"<<endl;
cout<<"B. Fahrenheit to Celsius"<<endl;
cout<<"Enter choice: ";
cin>>choice;
switch(choice){
case 'A':
cout<<"Enter temperature in Celsius: ";
cin>>celcius;
fahrenheit = (9.0/5.0) * celcius + 32;

cout<<"In Fahrenheit that is: "<<fahrenheit;


cout<<endl<<endl;
break;

case 'B':
cout<<"Enter temperature in Fahrenheit: ";
cin>>fahrenheit;

celcius = (fahrenheit - 32) * (5.0/9.0);

cout<<"In Celsius that is: "<<celcius;


cout<<endl<<endl;
break;

default:
cout<<"Invalid choice!!!";
cout<<endl<<endl;
break;
}
}while(ans==false);

return 0;
}
2. Create a program that will produce this output: Enter three
numbers: First number: 10 Second number: 20 Third number: 55 The
largest number is

#include<iostream>

using namespace std;

int main(){
int num1, num2, num3;

cout<<"Enter three numbers: "<<endl;


cout<<"First number: ";
cin>>num1;

cout<<"Second number: ";


cin>>num2;

cout<<"Third number: ";


cin>>num3;

if(num1>num2 && num1>num3){


cout<<"The largest number is: "<<num1;
}

else if(num2>num1 && num2>num3){


cout<<"The largest number is: "<<num2;
}
else{
cout<<"The largest number is: "<<num3;
}

return 0;
}
Please use switch statement
1. Create a C++ program that will produce this output:
Enter a radius: __
=====Circle Computation=====
A. Compute Area
B. Compute Diameter
C. Compute Circumference
Enter choice: _
If the choice is A, it will display the area of a circle;
If the choice is B, it will display the diameter of a circle;
If the choice is C, it will display the circumference of a circle;
If you entered a choice that is not among the options it will display
INVALID CHOICE!!!

#include<iostream>

using namespace std;

int main(){
char choice;
float PI = 3.141;
double radius, area, diameter, circumference;
bool ans = false;

cout<<"Enter a radius: ";


cin>>radius;

do{
cout<<"=====Circle Computation====="<<endl;
cout<<"A. Compute Area"<<endl;
cout<<"B. Compute Diameter"<<endl;
cout<<"C. Compute Circumference"<<endl;

cout<<"Enter choice: ";


cin>>choice;

switch(choice){
case 'A':
area = PI * radius * radius;
cout<<"Area of a circle is: "<<area<<endl<<endl;
break;

case 'B':
diameter = 2 * radius;
cout<<"Diameter of a circle is:
"<<diameter<<endl<<endl;
break;

case 'C':
circumference = 2 * PI * radius;
cout<<"Circumference of a circle is:
"<<circumference<<endl<<endl;
break;

default:
cout<<"INVALID CHOICE!!!"<<endl<<endl;
}
}while(ans==false);
return 0;
}

You might also like