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; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Great service! I had an assignment theory to be done and wasn't specific enough from my side on what I exactly needed it for. Even after messaging the expert one day before, they had it done the next day by the time I requested last minute.
Comments
Leave a comment