Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Small program won't compile... what is this error message?  (Read 2859 times)

0 Members and 1 Guest are viewing this topic.

tropophyte

    Topic Starter


    Newbie

    Small program won't compile... what is this error message?
    « on: February 18, 2009, 09:28:13 PM »
    Compiler shows me this, but I can't seem to see what I'm missing. 
    main.cpp:45: error: expected `}' at end of input


    There are two files this main.cpp and also a template at bottom:

    #include<iostream>      //C++ standard library header file I/O definitions
    #include "file.h"              //The template file file.h is included here
    using namespace std;      //Contains classes, objects and functions in the C++ library - no std :: scope
    using namespace duram;   //Resolves conflicting functions or variable names between the two libraries.

    void instruct (void);

    int main(int argc, char ** argv)   
                   
    {
    instruct();         

    int a[7] = { -4, -2, 0, 2, 4, 6, 7 };
    double b[7] = { -7.5, -4.3, 0, 6, 4.4, 8.2, 9.6 };

    int v;

    cout << "The integers in array a are: ";
    display<int>(a,7);
    cout << "The real numbers in array b are: ";
    display<double>(b,7);
    cout << "The integers smaller than 4 in a are: ";
    cout << count<int>(a,7,v);
    cout << "The real numbers smaller than 4 in b are: ";
    cout << count<double>(b,7,v);

    return 0;    
    }

    void instruct(void)
    {
    cout << endl << endl << "This program utilizes initialized arrays full of 7 digits" << endl;   //instructions for user
    cout << "and displays those array values using one template and" << endl;         //instructions for user
    cout << "finds and returns the quantity of values within less than 4." << endl << endl;   //instructions for user
    }




    TEMPLATE file.h

    #include<iostream>   
    using namespace std;
    namespace duram   
    {
    template<typename T>   
    void display(T*a, int N){
    for (int i=0; i<N; i++)
    cout << a << "  ";
    }


    template<typename T>
    T count(T*a, int N, T v) {
    int counter = 0;   
    for(int i=0; i<N; i++)
    { if (a<v)
    counter++;
    }
    return counter;
    }





    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Small program won't compile... what is this error message?
    « Reply #1 on: February 18, 2009, 11:21:47 PM »
    It would seem that you have a mismatch of the {

    Wen showing us code, use the code thing.

    Code: [Select]
    {
    template<typename T>   
    void display(T*a, int N){
    for (int i=0; i<N; i++)
    cout << a << "  ";
    }
    Otherwise you turn on the formulating tokens used on tis SMF board. The code above looks like you have an extra { at the end of a line.


    Dias de verano

    • Guest
    Re: Small program won't compile... what is this error message?
    « Reply #2 on: February 19, 2009, 12:16:07 AM »
    Code: [Select]
    #include<iostream>   
    using namespace std;
    namespace duram   
    {
    template<typename T>   
    void display(T*a, int N){ <------------------------------------------
    for (int i=0; i<N; i++)
    cout << a << "  ";
    }