This for C+ class, and use Notepad in PC for writing the program please it\'s ve
ID: 3887043 • Letter: T
Question
This for C+ class, and use Notepad in PC for writing the program please it's very important to use Notepad in PC Numerals Programming Assignment Your programming assignment is a step in the process toward the Roman Numeral generator. You must ask the user for a 4 digit number. Then you need to split the number into it's ones, tens, hundreds and thousands place values and display each value. (Hint: Simple modular arithmetic and division can get you your required result.) You must use mathematical expressions to split the four digit number into it's place values. An example output would look like this: Please enter a 4 digit number 1982 2 The one's place value is: The ten's place value is: The hundred's place value is: 9 The thousand's place value is:Explanation / Answer
#include <iostream>
#include <math.h>
using namespace std;
// first we call the header files
int main()
{
int number,i,value;
cout<<"Please enter a four digit number:";
cin>>number;
for(i=3;i>=0;i--){
value=int(number/pow(10,i))%10;
switch(i+1){
case 4:
cout<<"The one's place value is: "<<value<<endl;
break;
case 3:
cout<<"The ten's place vlaue is: "<<value<<endl;
break;
case 2:
cout<<"The hundred's place value is: "<<value<<endl;
break;
case 1:
cout<<"The thousand's place value is: "<<value<<endl;
break;
default:
break;
}
}
return 0;
}
/* pow(x,y) function is used from math.h which does the power operation to get the respective place value.*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.