Write a program that prompts the user for two integer numbers (called number1_in
ID: 3662558 • Letter: W
Question
Write a program that prompts the user for two integer numbers (called number1_int and number2_int) and two floating-point numbers (called number1_float and number2_float). Perform the following operations on the numbers:
* Add number1_int and number2_int together and print the result as an integer value
* Subtract number1_float from number2_float and print the result as a floating-point value
* Multiply number1_int by number1_float and print the result as an integer value * Divide number1_int by number2_int and print the result as an integer and a floating-point value (Ask yourself: What happens when you divide and integer by and integer? Does the result change because you print it as a floating-point number?)
* Divide number1_int by number2_float and print the result as an integer and a floating-point value (Ask yourself: How does this compare to the previous operations? We are now dealing with mixed data types.)
* Explicitly cast number1_int as a floating-point value and divide by number2_int. Print the result as a floating-point value.
* Try to mod number1_float by number2_float. Does the program compile? If not, fix it so that it does.
* Determine if number1_int and number2_int are even or odd. Print 0 if even and 1 if odd. You may not use “if” statements. Use the mod operator instead.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
void main()
{
int number1_int, number2_int;
float number1_float, number2_float;
cout<<"Enter 2 integers";
cin>>number1_int>>number2_int;
cout<<"Enter 2 floats";
cin>>number1_float>>number2_float;
int a=number1_int + number2_int;
cout<<a<<endl;
float b=number2_float - number1_float;
cout<<b<<endl;
int c=number1_int * number1_float;
cout<<c<<endl;
int d=number1_int/number2_int;
float d1=number1_int/number2_int;
cout<<d<<d1<<endl;
int e=number1_int /number2_float;
float e1=number1_int /number2_float;
cout<<e<<e1<<endl;
float f=float(number1_int)/number2_int;
cout<<f<<endl<<endl;
int g=int(number1_float)%int(number2_float);
cout<<g<<endl;
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.