This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.cpp | |
// type_ranges | |
// | |
// Created by Ahmad Ibrahim on 11/3/11. | |
// Copyright 2011 __MyCompanyName__. All rights reserved. | |
// | |
#include <iostream> | |
#include <iomanip> | |
using namespace std; | |
void wrong_calc(); | |
void correct_calc(); | |
int main (int argc, const char * argv[]) | |
{ | |
wrong_calc(); | |
correct_calc(); | |
return 0; | |
} | |
void wrong_calc() | |
{ | |
int num = INT_MAX; | |
num = num * 10 / 10; | |
cout <<"Wrong Value " << setw(20) << num << endl; | |
} | |
void correct_calc() | |
{ | |
int num = INT_MAX; | |
num = static_cast<double>(num) * 10 / 10; | |
cout<< "Correct Value" << setw(20) << num << endl; | |
} |
Wrong Value -1
Correct Value 2147483647
No comments:
Post a Comment