User writes 2 numbers. How much is the whole part of the number and how much is the decimal part of the number.
I am new to this, and i tried to write a program but i completely failed it. Please help! It also has to ask the user if he wants to restart the program after 2 numbers being entered.
int _tmain(int argc, _TCHAR* argv[])
{
float ncs;
long cd;
float ncds;
short i;
i=1;
for(;i<= 2;)
{
cout<<"Enter a decimal number"<<endl;
cin>>ncs;
cd=(long)ncs;
ncds=ncs-cd;
cout<<setprecision(2)<<"For "<<i+1<<". the number that is "<<ncs<<" is ";
cout<<"decimal part= "<<ncds<<", the whole part: ";
cout<<cd<<endl;
i=i+1;
}
system("pause");
return 0;
}
If your grader is a stickler about rounding errors when there are too many decimal places or handling overflow for numbers that are too large, you may need to elaborate to prevent a user from inputting such data.