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!
1
Expert's answer
2012-10-02T09:57:04-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS