Output error

I cant get this to work, i wanted to output the random names but it wont output it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <iostream>
#include <string>
#include <fstream>
#include <random>
#include <ctime>

using namespace std;

class Vars
{
    public:
        void MainProgram();
        void Names();
        void setStrings(string PNAME, string BNAME)
        {
            pname = PNAME;
            bname = BNAME;
        }
        string getPname()
        {
            return pname;
        }
        string getBname()
        {
            return bname;
        }

        void setIntegers(int MONEY, int XP)
        {
            money = MONEY;
            xp = XP;
        }
        int getMoney()
        {
            return money;
        }
        int getXp()
        {
            return xp;
        }
    private:
        string pname;
        string bname;
        int money;
        int xp;
};

int main()
{
    Vars v;
    string pname, bname;
    string choice;

      while(choice != "1")
    {
        cin.sync();
        cout << "Please enter the name of your bank (dont put bank in the name)" << endl;
        getline(cin, bname);

        cout << "\n";

        cout << "Please enter your name" << endl;
        getline(cin, pname);

        cout << "\n";

        cout << "So your Bank name is " << bname << " ?\n" << endl;

        cout << "and your Name is " << pname << " ?\n" << endl;

        cout << "Please enter 1 for YES or 2 for NO" << endl;

        cin >> choice;

        if(choice == "1")
            {
                v.setStrings(pname, bname);
                v.MainProgram();
                break;
            }
    }
}

void Vars::MainProgram()
{
    Vars v;
    int TIME;

    time_t T;
    ctime(&T);
    srand(time (NULL));

    TIME = rand() % 5;

    v.setStrings(pname, bname);

    cout << "Welcome " << pname << " to " << bname << " bank" << endl;
    cout << "Press ENTER to begin\n" << endl;
    cin.sync();
    cin.get();

    while(true)
    {
        switch(TIME)
        {
            case 0:
                cout << "Hi my name is" << v.Names() << endl;
        }
    }
}

void Vars::Names()
{
    int TIME2;

    time_t T;
    ctime(&T);
    srand(time (NULL));

    TIME2 = rand() % 5;

    switch(TIME2)
    {
        case 0:
            cout << "John";
            break;
        case 1:
            cout << "Mark";
            break;
        case 2:
            cout << "Angela";
            break;
        case 3:
            cout << "Tiffany";
            break;
        case 4:
            cout << "Alex";
            break;
    }
}



ERRORS:


C:\Users\Chay Hawk\Desktop\Money Manager\main.cpp||In member function 'void Vars::MainProgram()':|
C:\Users\Chay Hawk\Desktop\Money Manager\main.cpp|107|error: no match for 'operator<<' in 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(& std::cout)), ((const char*)"Hi my name is")) << v.Vars::Names()'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|108|note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|117|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|127|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|165|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|169|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|173|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\ostream.tcc|91|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|180|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\ostream.tcc|105|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|191|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|200|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|204|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|209|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|213|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|221|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\ostream|225|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\ostream.tcc|119|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]|
||=== Build finished: 1 errors, 0 warnings ===|
error: no match for 'operator<<' in 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(& std::cout)), ((const char*)"Hi my name is")) << v.Vars::Names()'|
cout << "Hi my name is" << v.Names() << endl;

So what is the return type of Names()?
Last edited on
im not sure. return type?
Last edited on
http://cplusplus.com/doc/tutorial/functions/
(return) type is the data type specifier of the data returned by the function.
oh, yeah return, well there isnt really a type i dont think there just cout statements.

i did this

v.Names(TIME2)

and it just gives me this


C:\Users\Chay Hawk\Desktop\Money Manager\main.cpp||In member function 'void Vars::MainProgram()':|
C:\Users\Chay Hawk\Desktop\Money Manager\main.cpp|107|error: 'TIME2' was not declared in this scope|
||=== Build finished: 1 errors, 0 warnings ===|
Last edited on
or is it TIME2? im confused a bit, i read that link but dont really understand it any better.
Topic archived. No new replies allowed.