number devision

Here m would be the first part of decimal point and n would be the second part of decimal point,how can i do that?

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;
int main()
{
   int a,b,m,n;
   double s;
   cin>>a;
   cin>>b;
   s=a/b;
   cout<<"you get " << m <<"500 dollars and"<<n<<100 dollars; 
    system("pause");
    return 0;
}

Last edited on
Your code in combination with your question makes no sense at all. Please rephrase.

http://www.cplusplus.com/articles/jEywvCM9/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>

int main()
{
    std::cout << "Enter a decimal number: " ;

    double num ;
    std::cin >> num ;

    std::cout << "Whole part: " << static_cast<int>(num)
              << "\nDecimal part: " << num - static_cast<int>(num) << '\n' ;

    std::string s ;

    std::cout << "Enter another decimal number: " ;
    std::cin >> s ;

    std::cout << "Whole part: " ;
    unsigned i=0;
    while ( i < s.length() && s[i] != '.' )
        std::cout << s[i++] ;

    std::cout << "\nDecimal part: " ;
    while( ++i < s.length() )
        std::cout << s[i] ;
    std::cout << '\n' ;
}
you can take the input as a string and use the logic given by cire
#include<iostream.h>
int main()
{
char s[10];
cout<<"enter the decimal number";
cin>>s;
cout<<"whole part is:";
for(int i=0;s[i]!='.';i++)
cout<<s[i];
cout<<"decimal part is:";
while(s[i]!='\0')
{
cout<<s[i];
i++;
}
return 0;
}
Thanks both of You :)
Last edited on
Topic archived. No new replies allowed.