Image

Imagepaper_crystals wrote in Imagecpp

help


# include
# include
# include

using namespace std;

void GetNumber(int&);
void ConvertToBase(int&, int&);


int main()
{
int userNum;//number the user inputs
int baseNum;//number converted to base 16

GetNumber(userNum);
//gets number from the user
ConvertToBase(userNum, baseNum);

return 0;
}

void GetNumber(int&/*out*/ userNumGet)
{
cout<<"Please enter an integer. This program will give"<
[Error: Irreparable invalid markup ('<endl;>') in entry. Owner must fix manually. Raw contents below.]

<lj-cut text="Why do I keep getting 66 instead of 'B' or at least 11 when I put in 11 for this code? It is probably something painfully simple but I am really confused.">
# include <iostream>
# include <string>
# include <cmath>

using namespace std;

void GetNumber(int&);
void ConvertToBase(int&, int&);


int main()
{
int userNum;//number the user inputs
int baseNum;//number converted to base 16

GetNumber(userNum);
//gets number from the user
ConvertToBase(userNum, baseNum);

return 0;
}

void GetNumber(int&/*out*/ userNumGet)
{
cout<<"Please enter an integer. This program will give"<<endl;
cout<<"you that integer in base 16."<<endl<<endl;
cout<<"Integer: ";
cin>>userNumGet;
}
void ConvertToBase(int&/*in*/userNumCon, int& baseNumCon)
{
baseNumCon = userNumCon % 16;
userNumCon = userNumCon / 16;

if (baseNumCon == 10)
baseNumCon = 'A';
if (baseNumCon == 11)
baseNumCon = 'B';
cout<<baseNumCon;

while(userNumCon != 0)
{
baseNumCon = userNumCon % 16;
userNumCon = userNumCon / 16;

if (baseNumCon == 10)
baseNumCon = 'A';
if (baseNumCon == 11)
baseNumCon = 'B';
cout<<baseNumCon;
}

}

</lj-cut>