I am having trouble rounding a GPA double to 2 decimal places. (ex of a GPA needed to be rounded: 3.67924) I am currently using ceil to round up, but it currently outputs it as a whole number (368)
here is what I have right now
if (cin >> gpa) { if (gpa >= 0 && gpa <= 5) { // valid number gpa = ceil(gpa * 100); break; } else { cout << "Please enter a valid GPA (0.00 - 5.00)" << endl; cout << "GPA: "; } }
using the above code with 3.67924 would output 368 (which is what I want, but just without the period between the whole number and the decimals). How can I fix this?
Related Posts:
- std::cin.getline( ) vs. std::cin
- When and why do I need to use cin.ignore() in C++?
- Why would we call cin.clear() and cin.ignore() after reading input?
- cin >> “no operator matches these operands”
- Press Enter to Continue
- cin >> “no operator matches these operands”
- Correct way to use cin.fail()
- Checking cin input stream produces an integer
- Reading getline from cin into a stringstream (C++)
- std::cin input with spaces?
- How do I flush the cin buffer?
- cin.ignore(numeric_limits
::max(), ‘\n’) - Using cin for char array
- Using cin to input a single letter into a char
- Multiple inputs on one line
- Pause Console in C++ program
- Why the switch statement cannot be applied on strings?
- C++ string to double conversion
- How do I print out the contents of a vector?
- ‘was not declared in this scope’ error
- Good input validation loop using cin – C++
- C++ for each, pulling from vector elements
- How do I erase an element from std::vector<> by index?
- Incomplete Type Is Not Allowed
- how to implement quick sort algorithm in C++
- Why use ‘glad’ library for opengl initialization? [duplicate]
- What does `*&` in a function declaration mean?
- (->) arrow operator and (.) dot operator , class pointer
- Initializing a two dimensional std::vector
- What does “<<" and ">>” mean in C++ for cout/cin?
- C ++ error: a expected initializer before [function name]
- invalid new-expression of abstract class type
- std::string to char*
- Exception Error c0000005 in VC++
- push_back vs emplace_back
- Returning multiple values from a C++ function
- Eclipse C++ : “Program “g++” not found in PATH”
- no default constructor exists for class
- How to trim a std::string?
- Parsing a comma-delimited std::string
- Random number c++ in some range
- Convert a String In C++ To Upper Case
- Is std::stoi actually safe to use?
- Visual Studio 2015 doesn’t have cl.exe
- Right way to split an std::string into a vector
- How to resize array in C++?
- C++: std does not have member “string”
- Fatal error: ‘stdafx.h’ file not found
- How do I add the MinGW bin directory to my system path?
- What’s the syntax for declaring an array of function pointers without using a separate typedef?
- What is the difference between const_iterator and non-const iterator in the C++ STL?
- Sorting Linked List C++ with pointers
- Get Unix timestamp with C++
- Class prototyping
- How to dynamically allocate an array of pointers in C++?
- Error C1083: Cannot open include file: ‘stdafx.h’
- How do you handle a “cannot instantiate abstract class” error in C++?
- How to cast the size_t to double or int C++
- How to get Current Directory?
- “used without template parameters”
- Reading from .txt file into two dimensional array in c++
- C++ Error ‘nullptr was not declared in this scope’ in Eclipse IDE
- C++ Simple hangman game
- “The system cannot find the file specified” when running C++ program
- Remove First and Last Character C++
- C++ Convert string (or char*) to wstring (or wchar_t*)
- Program received signal SIGSEGV, Segmentation fault
- Integer to hex string in C++
- Comparison of C++ unit test frameworks
- Why is inherited member not allowed?
- Error: macro names must be identifiers using #ifdef 0
- Error: free(): invalid next size (fast):
- Error: free(): invalid next size (fast):
- Fastest way to Convert String to Binary?
- Reading data from file into an array
- LINK : fatal error LNK1561: entry point must be defined ERROR IN VC++
- Trying to use int in getline
- c++ error c2015: too many characters in constant
- Splitting a C++ std::string using tokens, e.g. “;”
- Stack around the variable ‘ ‘ was corrupted
- The difference between cin.ignore and cin.sync
- casting int to char using C++ style casting
- How to print (using cout) a number in binary form?
- What is the job of autogen.sh when building a c++ package on Linux
- Using G++ to compile multiple .cpp and .h files
- LPCSTR, LPCTSTR and LPTSTR
- How to do std::string indexof in C++ that returns index of matching string?
- variable or field declared void
- Invalid conversion from ‘char’ to ‘const char *’
- How do I deal with “signed/unsigned mismatch” warnings (C4018)?
- Creating folders in C++
- Modulo operator with negative values [duplicate]
- Finding the type of an object in C++
- C++ Simple Dice roll – how to return multiple different random numbers [duplicate]
- How can I get a file’s size in C++?
- Why can’t I make a vector of references?
- What does “-Wall” in “g++ -Wall test.cpp -o test” do?
- C++ equivalent of StringBuffer/StringBuilder?
- heap corruption detected | C++
- Update g++ but still old version