I'm trying to create a simple program which converts a decimal number into hexadecimal. I'm trying to keep it done in ways that aren't super complex and advanced since I am a beginner. Obviously I like to try to keep it in terms of my own code without just taking someone's work and turning it in as mine but I'm a beginner and seeing others' code is kind of inevitable to get started. "Why reinvent the wheel?" as my friend always says.
This is being done using selection rather than looping seeing as my instructor strictly said to not use loops. I pretty much have it down but right now I am stumped as to why I receive the "unable to resolve function overload" error.
The input is contained in a text file and the output is also to be contained in a text file. I think I pretty much have it down but I am still a it confused as to why it doesn't compile. I followed http://robustprogramming.com/convert-decimal-to-hex-cpp/ and I recognized the switch method that my instructor used in class.
#include "convert.h"
#include <iostream>
#include <string>
#include <fstream> //for file stream
using std::endl;
using std::string;
using std::cin;
using std::cout;
using std::ifstream;//input file stream
using std::ofstream;//output file stream
void conversion(int number, int base);
int main( )
{
ifstream in("input.txt");
ofstream out("output.txt");
string word;
unsignedint mynumber;
int base;
base = 16;
in >> word;
in >> mynumber;
out << "Converted: " << word << endl;
out << "Original Number: " << mynumber << endl;
out << "Converted Number: "; conversion(mynumber, base); endl;
return 0;
}
void conversion(int number, int base)
{
ofstream out("output.txt");
if( number > 0 )
{
conversion( number/base , base );
switch(number%base)
{
case 10 :
out << "A";
break;
case 11 :
out << "B";
break;
case 12 :
out << "C";
break;
case 13 :
out << "D";
break;
case 14 :
out << "E";
break;
case 15 :
out << "F";
break;
default :
out << number%base;
break;
}
}
}