0

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");
}
Andrew
  • 17
  • 1
  • *it just calculates scientific notations* -- No, it is *displaying* scientific notation. The goal is to format the display correctly (`iomanip`, `std::format`, etc.). – PaulMcKenzie Feb 25 '22 at 17:36
  • Can you show me an example on how iomanip works? – Andrew Feb 25 '22 at 17:48

1 Answers1

0

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");
}
Cyber0
  • 1
  • 4