'I'm trying to make a small calculator in C++ but it only calculates scientific notations [duplicate]
I'm new to C++ and to start off I'm making a multiplication calculator. The problem is whenever I do numbers over ~1000 it just calculates scientific notations. The code is below, can anyone help?
#include <iostream>
using namespace std;
int main()
{
float value;
cout << "Please enter value ";
cin >> value;
float multBy;
cout << "\nWhat would you like to multiply by? ";
cin >> multBy;
float answer = value * multBy;
cout << "\nYour answer is " << answer;
system("pause>0");
}
Solution 1:[1]
The following is modified code of yours. By the use of showpoint and fixed , the results are displayed in fixed point notation and by the use of "setprecision" we can adjust the numbers after decimal in result.
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{ float value;
cout << "Please enter value ";
cin >> value;
float multBy;
cout << "\nWhat would you like to multiply by? ";
cin >> multBy;
float answer = value * multBy;
cout << "\nYour answer is " <<showpoint<<fixed<<setprecision(2)<<answer;
system("pause>0");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
