View Code of Problem 96

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
int main()
{
	int n;
	char c[3];
	double sum = 0;
	while (cin >> n) {
		cin >> c;
		if (n == 0)	{
			break;
		}
		if (c[0] == 'B') {
			cout << 0<<endl;
		}
		if (c[0] == 'K') {
			sum = n * (1024 - 1000);
			cout << fixed << setprecision(0)<< sum<<endl;
		}
		if (c[0] == 'M') {
			sum = n * (1024.0 * 1024 - 1000.0 * 1000);
			cout << fixed << setprecision(0)<<sum <<endl;
		}
		if (c[0] == 'G') {
			sum = n * (1024.0 * 1024 * 1024 - 1000.0 * 1000 * 1000);
			cout << fixed << setprecision(0)<<sum<<endl;
		}
		if (c[0] == 'T') {
			sum = n * (1024.0 * 1024 * 1024 * 1024 - 1000.0 * 1000 * 1000 * 1000);
			cout <<fixed<<setprecision(0)<< sum <<endl;
		}
	}
}

Double click to view unformatted code.


Back to problem 96