[
#include <iostream>
#include <string>
using namespace std;
class digits
{
};
class numOutofRange
{
};
int string_to_int(string s)
throw(digits, numOutofRange);
int main()
{
int histogram[10];
int total;
int currentNumber = 0;
string s;
for(int i=0; i < 10; i++)
{
histogram[i] = 0;
}
cout <<"How many numbers do you have to enter? ";
cin >> total;
while(currentNumber < total)
{
cout <<"Enter number: " << currentNumber + 1 << " : " << endl;
string s;
cin >> s;
try
{
int value;
//value = string_to_int(s);
histogram[value - 1]++;
currentNumber++;
}
catch(numOutofRange)
{
cout <<"Enter only a number between 1 and 10" << endl;
}
}
cout <<"Histogram values: " << endl;
for(int i = 0; i < 10; i++)
{
cout << i + 1 <<" : ";
for(int j = 0; j < histogram[i]; j++)
{
cout <<"*";
}
cout << endl;
}
}
///////////////////////////////////////////////
int string_to_int(string s)
throw(digits, numOutofRange)
{
for(int i = 0; i < s.length(); i++)
{
char c = s[i];
if((c = '0') || (c > '9'))
throw digits();
}
int value = atoi(s.c_str());
if((value < 1) || (value > 10))
throw numOutofRange();
return value;
}
this is my code and i am getting a linking error. i comented out where i think the linker error is and if someone can help me fix it i would appreciate it.