Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what's the problem with that code? C++

+1 vote
asked Apr 24 by Christina Rapti (130 points)
#include<iostream>
using namespace std;
int main ()
{
  double a, d;
  int i;
  cin >> a;
  i = a;
  d = a-i;
  cout << i << endl;
  cout << d << endl;
  return 0;
}

4 Answers

+3 votes
answered Apr 25 by Manuel Mateo (1,170 points) 1 flag
Your question is a little vague, what do you want your program to do?
0 votes
answered Apr 27 by gfrve dfss (340 points)
reshown Apr 28 by gfrve dfss
mabe the double????
0 votes
answered Apr 28 by gtgtr (150 points)

  

cin >> a;   //let suppose i enterd 50
  i = a;         //Here you are storing storing value of a in i so both will be 50
  d = a-i;     //than you did a-i that means 50-50 because you stored 50 in both a and i
  cout << i << endl;  //than you printed the value of i which was 50
  cout << d << endl; //here you printed d which is a-i means 50-50 which is equal to zero
  return 0;

There is no problem in the program.

Well you can write the program in a  better way so that you can understand what you have written. 

Example:

{
  double a, d;
  int i;
  cout<<"Enter Number ";
  cin >> a;
  i = a;
  d = a-i;
  cout <<"You Enterd " << i << endl;
  cout <<"So " << i <<" - "<< i <<" = "<< d << endl;
  return 0;

well this program is easy to understand.

0 votes
answered May 5 by arunthesun (180 points)

int main ()
{
  double a, d;
  int i;
  cin >> a;
  i = a; // a double (64-bit floating point) value is getting truncated to an integer (32-bit non-floating point) value. Intentional ?
  d = a-i;
  cout << i << endl;
  cout << d << endl;
  return 0;
}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...