I don't know what this error means...

I am so close to finishing my program but I don't know what this error means or how to fix it.
1
2
 numbersystem.cpp:142: error: invalid conversion from ‘int’ to ‘const char*’
numbersystem.cpp:142: error:   initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]


here is my program..
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
@file numbersystem.cpp
@author Margaret Fink
@date 2011- 04-14
Description: Menu-driven application that performs conversions among
numbers of different bases.
Course: CS1253 Section: 2
Logon ID: cs125377
Programming Project #: 5
Instructor: Duncan
*/

# include <iostream>
# include <cmath>

using namespace std;

/*
* This function display the menu shown in this
* project description
*/
void menu()
{
   cout<<"     NUMBER SYSTEM APPLICATION   "<<endl;
   cout<<"===================================="<<endl;
   cout<<"[1] Base-10 -> Nonbase-10"<<endl;
   cout<<"[2] Nonbase-10 -> Base-10"<<endl;
   cout<<"[3] Nonbase-10 -> Nonbase-10"<<endl;
   cout<<"[0] Exit"<<endl;
   cout<<endl;
}

/*
* This function returns the value of the digit
* of a non base 10 number.
* @param digit a character 0-9 or A-Z
* @ return 1 for the character ’1’, 2 for the
* character ’2’, ..., 10 for the character ’A’,
* 11 for the character ’B’, 12 for the character
* ’C’, etc.
*/
char valueToDigit(int value)
{
   if(0 <= value <= 9)
      value = value + 48;
   else
      value = value + 55;
   return value;
}

/*
* This function converts a base-10 number to
* a string equivalent to a non-base 10 number.
* @param base10Num a non-negative integer
* @param base a number greater than 1 representing
* the base to which the base10Num is to be converted.
* @return a string representing the base b
* equivalent of the base 10 number.
*/
string fromBase10(long base10Num, long base)
{
   string ans = " ";
   int remain;
   int Q = base10Num;
   while(Q != 0)
   {
      remain = (Q % base);
      Q = Q/base;
      ans = valueToDigit(remain);
   }
   return ans;
}

/*
* This function converts a non base 10 number to
* a base 10 number.
* @param nonBase10Num a string representation of
* a non-base 10 number; nonBase10Num
* is assumed to be a valid number in the indicated base.
* @param base a number greater than 1 representing
* the base of the nonBase10Num.
* @return the base 10 equivalent on the non-base 10
* number, nonBase10Num.
*/
long toBase10(string nonBase10Num , long base)
{
   int i;
   int j;
   int base10;
   for(i = nonBase10Num.length() - 1; i >= 0; i--)
   {
   digitToValue(nonBase10Num[i]);
      base10 = nonBase10Num[i] * pow(base,j);
      j++;
   }
   return base10;
}

int main()
{
   int option;
   do
   {
      menu();
      cout<<endl;
      cout<<"Select an option.";
      cin>>option;
      switch(option)
      {
         case 1: cout<<"Enter a non-negative integer:";
                 int integer;
                 cin>> integer;
                 cout<<"To which base should it be converted?";
                 int baseConvrt;
                 cin>>baseConvrt;
                 fromBase10(integer,baseConvrt);
                 cout<<integer<<" = "<<fromBase10<<" base "<<baseConvrt<<endl;
                 break;

case 2: cout<<"Enter a non base-10 number:";
                 int nonBase;
                 cin>> nonBase;
                 cout<<"To whish base does this number belong?";
                 int baseNum;
                 cin>> baseNum;
                 toBase10(nonBase,baseNum);
                 cout<<nonBase<<" = "<<toBase10<<" base "<<baseNum<<endl;
                 break;
         case 3: cout<<"Enter a non base-10 number:";
                 cin>> nonBase;
                 cout<<"To which base does this number belong?";
                 int base;
                 cin>> base;
                 cout<<"To which base should it be converted?";
                 cin>> baseConvrt;
                 toBase10(nonBase,base);
                 fromBase10(toBase10,baseConvrt);
                 cout<<nonBase<<" = "<<fromBase10<<" base "<<baseConvrt;
                 break;
         case 0:
                 break;
         default:
                 cout<<"Invalid option... please try again."<<endl;
      }
   }while(option != 0);
   return 0;
Last edited on
Line 126 seems to be your problem, you are passing an integer "nonBase" as the first argument to a function that is expecting an std::string.
check the valueToDigit function. that functions type is char but the value returned is an int - return value;
value should be of type char.
yeah i think the function return value got problem. as for the solution, you can try to map the integer value to char and return the char value back to the function as the function is supposed to return character.

char valueToDigit(int value)
{
if(0 <= value <= 9)
value = value + 48;
else
value = value + 55;
return value;
}


Topic archived. No new replies allowed.