Thread: Help with outputting a list of squared numbers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    110

    Help with outputting a list of squared numbers

    So my program is suppose to take in a single number and output all numbers starting from 0 up to that given number squared. I believe this is quite an easy problem but I am struggling with it when it includes headers and source files. I am getting an 'undefined reference to 'squaredint...'' error. I do not understand why it is getting this error though, but I do see where it occurs.
    Here is the coding for my main, source, and header files.

    main
    Code:
    #include "squaredintheader.h"
    #include <conio.h>
    #include <iostream>
    
    using std::cout;
    using std::endl;
    using std::cin;
    
    int main(){
        
        int num;
        
        cout << "Up to what number do you want squared? " << endl;
        cin >> num;
        
        //the whole squared numbers
        number_info numbers = squaredint(num, numbers);
        
        //outputs the number with the squared numbers
        for(int i = 0; i != numbers.number.size(); i++){
                cout << i << " " << numbers.squared[i] << endl;
                }
                
        cout << "Press enter to continue..";
        _getch();
        return 0;
        }
    header
    Code:
    #ifndef GUARD_squarednum_h
    #define GUARD_squarednum_h
    
    #include <vector>
    
    //squaredintheader.h
    struct number_info{
           std::vector<int> number;
           std::vector<int> squared;
    };
    
    number_info squaredint(const int&, number_info&);
    
    #endif
    source
    Code:
    #include "squartedintheader.h"
    #include <vector>
    
    using std::vector;
    
    number_info squaredint(const int& upto, number_info& squaredlist){
               
                //adds the given number and squared number
                //to the struct of int vectors
                for(int i = 0; int != upto; i++){
                        squaredlist.number.push_back(i);
                        squaredlist.squared.push_back(i*i);
                        }
                }
    Thanks for your help!
    Last edited by dnguyen1022; 01-15-2009 at 03:57 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Outputting a list of squared Doubles
    By dnguyen1022 in forum C++ Programming
    Replies: 13
    Last Post: 01-19-2009, 01:24 PM
  3. Recursion Revisited again, and again!
    By clegs in forum C++ Programming
    Replies: 93
    Last Post: 12-08-2007, 08:02 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM