// Dick cs201/wrk/1.HELP! // Wed Apr 12 14:49:19 PDT 1995 // Example of converting an int variable to floating point // /* -------------Problem------------ From page 59..59. Integer division. Sometimes you need to get a floating point number by dividing one integer by another one. This program shows how you can do this in C++. -------------Analysis----------- DATA REQUIREMENTS Constants None Inputs Two integers x and y (int) Outputs The quotient (float) FORMULAE quotient = x/y, in mathematics. --------------Design------------- INITIAL ALGORITHM 1. get x and y from the user 2. calculate quotient = x/y 3. display quotient 4. calculate quotient = float(x)/y 5. display quotient REFINEMENTS 1. get x and y from the user 1.1 prompt for x 1.2 read x 1.3 prompt for y 1.5 read y ------------Implementation--------- */ #include #include //defines EXIT_SUCCESS etc int main( void ) { // declare variables here int x,y; float quotient; cout <<"enter an integer x="; cin >> x; cout <<"enter an integer y="; cin >> y; quotient= x / y; cout<< "x / y is " << quotient << endl; quotient= float(x) / y; cout<< "float(x) / y is " << quotient << endl; return EXIT_SUCCESS; }