Function Overloaded in Simple Program?

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#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;
	unsigned int 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;
        }
	}
}
Last edited on
out << "Converted Number: "; conversion(mynumber, base); endl;

Should be
1
2
out << "Converted Number: "; 
conversion(mynumber, base); 


You can't have endl by itself, you can add a line later with out << endl; if you wanted to.
Thanks, that fixed it. I'm dumb and was moving code around. I guess I just left out the out << before the endl.
Last edited on
Topic archived. No new replies allowed.