#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void main() {
int a, b;
while (cin >> a) {
switch (a) {
case 2: {
cin >> b;
std::string s = std::to_string(b);
int dec = std::stoi(s, nullptr, 2);
cout << dec << endl;break;
}
case 8:
cin >> b;
cout << oct <<b<< endl; break;
case 16:
std::cin >> std::hex >> b;
std::cout << b << std::endl;
}
}
}
that's my code.Every one of them works, but the hex one.When i use it once, then it's not working.
For example if i have an input:
2 1111
16 F
8 1
it should have an output:
15
15
1
the first number is hex/bin/oct and the second is the number you give.
About the while(cin>>a), it's that way because it should be kinda of endless cycle, there will be a lot of inputs and yeah.I guess it doesn't work because of that statement, but i don't know how to fix it.