I\'m just learning C++. It needs to work for decimal numbersas well as integers
ID: 3608145 • Letter: I
Question
I'm just learning C++. It needs to work for decimal numbersas well as integers but at this point will only work for integers(for the most part). If someone could tell me how to fix thisproblem it would be greatly appreciated. This is the programI've written so far#include <iostream>
using namespace std;
int main()
{
int number1;
int number2;
cout <<"ENTER NUMBER 1: ";
cin >> number1;
cout <<"ENTER NUMBER 2: ";
cin >> number2;
cout << number1 << "+" << number2 << "="<< number1 + number2 << endl;
cout << number1 << "-" << number2 << "="<< number1 - number2 << endl;
cout << number1 << "/" << number2 << "="<< number1 / number2 << endl;
cout << number1 << "*" << number2 << "="<< number1 * number2 << endl;
return 0;
}
and this is the output it gives (using integers):
ENTER NUMBER 1: 4
ENTER NUMBER 2: 5
4+5=9
4-5=-1
4/5=0
4*5=20
notice it says 4/5 is 0 and not .8
Explanation / Answer
//Dear, to use decimal , you willneed to use float, //hope this will help you.. #include using namespace std; int main() { float number1; float number2; cout number1; cout number2; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.