[

#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.

Recommended Answers

All 3 Replies

i fixed the linker error but now it stops running after i input the first number

I'd bet that it happens due to an uncaught exception of type digits . Hint: there is something wrong at line #72.

[EDIT]
Isn't your compiler giving a warning of any kind, have you checked?

Note that I'm assuming that you are actually calling the string_to_int() function.

i got it working but now it wont display my histogram

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.