# Answer to Question #15783 in C++ for sakura

Question #15783

Write a function for the following:

function that returns a value:

1.Convert whole number to decimal

Ex. 10

Output: 0.1

2. Convert decimal to whole number

Ex. 0.05

output: 5

The main program

3. Display the following:

[D] Convert whole number to decimal

[W] Convert decimal to whole number

[E] Exit

Enter your choice

Using switch call the functions

Thank you!

function that returns a value:

1.Convert whole number to decimal

Ex. 10

Output: 0.1

2. Convert decimal to whole number

Ex. 0.05

output: 5

The main program

3. Display the following:

[D] Convert whole number to decimal

[W] Convert decimal to whole number

[E] Exit

Enter your choice

Using switch call the functions

Thank you!

Expert's answer

#include <iostream>

using namespace std;

int main(){

char mark;

cout<< "What would you like?\n";

cout<<"_Convert to decimal - D\n";

cout<<"_Convert to whole number - W\n";

cout<<"Exit - E\n";

cin>>mark;

cout<<"Enter number!\n";

double num;

cin>>num;

if (mark == 'D') {

& num = 1 / num;

& cout<<"The answer is: "<<num;

}

else if (mark == 'W') {

& int i = 0;

& for (; int(num)%10 == 0;i++) num*=10;

& for (; int (num)%10 > 0; i++)

& num*=10;

& num /= 10;

& cout<<"The answer is: "<<num;

}

else {

& return 0;

}

cout<<endl;

system("pause");

return 0;

}

using namespace std;

int main(){

char mark;

cout<< "What would you like?\n";

cout<<"_Convert to decimal - D\n";

cout<<"_Convert to whole number - W\n";

cout<<"Exit - E\n";

cin>>mark;

cout<<"Enter number!\n";

double num;

cin>>num;

if (mark == 'D') {

& num = 1 / num;

& cout<<"The answer is: "<<num;

}

else if (mark == 'W') {

& int i = 0;

& for (; int(num)%10 == 0;i++) num*=10;

& for (; int (num)%10 > 0; i++)

& num*=10;

& num /= 10;

& cout<<"The answer is: "<<num;

}

else {

& return 0;

}

cout<<endl;

system("pause");

return 0;

}

## Comments

## Leave a comment