Why isn't this outputting anything?

main.cpp
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
#include <iostream>
#include "blah.h"

  int att1= 61, def1= 66, eva1=47, mid1=50, hp1=372,
   att2 = 62, def2 = 66, eva2 = 47, mid2 = 50, hp2 = 372,
   att3 = 50, def3 = 54, eva3 = 64, mid3 = 45, hp3 = 331,
   att4 = 49, def4= 52, eva4 = 58, mid4 = 69, hp4 = 356,
   att5 = 58, def5 = 80, eva5 = 50, mid5 = 48, hp5 = 389,
   att6 = 76, def6 = 64, eva6 = 60, mid6 = 59, hp6 = 401,
   att7 = 76, def7 = 59, eva7 = 57, mid7 = 54, hp7 = 422,
   att8 = 53, def8 = 45, eva8 = 45, mid8 = 52, hp8 = 253;
using namespace std;

int main()
{
   Test a; 
 
   a.theFunction(att1, def1, eva1, mid1, hp1);
   cout << att1 << " " << def1 << " " << eva1 << " " << mid1 << " " << hp1;
   cout << endl;
   a.theFunction(att2, def2, eva2, mid2, hp2);
   cout << att2 << " " << def2 << " " << eva2 << " " << mid2 << " " << hp2;
   cout << endl;
   a.theFunction(att3, def3, eva3, mid3, hp3);
   cout << att3 << " " << def3 << " " << eva3 << " " << mid3 << " " << hp3;
   cout << endl;
   a.theFunction(att4, def4, eva4, mid4, hp4);
   cout << att4 << " " << def4 << " " << eva4 << " " << mid4 << " " << hp4;
   cout << endl;
   a.theFunction(att5, def5, eva5, mid5, hp5);
   cout << att5 << " " << def5 << " " << eva5 << " " << mid5 << " " << hp5;
   cout << endl;
   a.theFunction(att6, def6, eva6, mid6, hp6);
   cout << att6 << " " << def6 << " " << eva6 << " " << mid6 << " " << hp6;
   cout << endl;
   a.theFunction(att7, def7, eva7, mid7, hp7);
   cout << att7 << " " << def7 << " " << eva7 << " " << mid7 << " " << hp7;
   cout << endl;
   a.theFunction(att8, def8, eva8, mid8, hp8);
   cout << att8 << " " << def8 << " " << eva8 << " " << mid8 << " " << hp8;
    
    
    return 0;
    
}

blah.h
1
2
3
4
5
6
7
8
#ifndef BLAH_H
#define BLAH_H
class Test
{     public:
      
      int theFunction(int& a, int& b, int& c, int& d, int& e);
      };
#endif 

blah.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "blah.h"
using namespace std;


int Test::theFunction(int& a, int& b, int& c, int& d, int& e)
{
    int globe = 0;
    while (globe < 10)
    {
    a += a/9;
    b += b/9;
    c += c/9;
    d += d/9;
    e += e/9;
    }
}
Your program is getting stuck in an infinite loop with Test::theFunction.

Try this instead:
1
2
3
4
5
6
7
8
9
10
int Test::theFunction(int &a, int &b, int &c, int &d, int &e) {
    int globe = 0;
    while (globe++ < 10) {
        a += a/9;
        b += b/9;
        c += c/9;
        d += d/9;
        e += e/9;
    }
}


Another thing:
You should probably be storing your data in a struct or something, rather than huge numbers of integers. That also means that you could simply pass the struct to your function, rather than having to pass each individual value.
It shouldn't even compile, but assuming it does, there is nothing for it to output.
closed account (Dy7SLyTq)
It shouldn't even compile, but assuming it does, there is nothing for it to output.

what are you talking about? i see no error and i see plenty to output
I didn't try it out, but shouldn't int theFunction() be returning something?
closed account (Dy7SLyTq)
i think you just get a warning but it should be void
I would get all kinds of hell in VS2010 if I forgot to return something, so I didn't look past that.
i think you just get a warning but it should be void

The MSVC and GCC delelopers obviously have a different take here:

MSVC wrote:
error C4716: 'Test::func' : must return a value


GCC wrote:
In member function 'int Test::func()':
warning: no return statement in function returning non-void [-Wreturn-type]


Andy

PS You can get the compilers to change their minds, if you want to.
Topic archived. No new replies allowed.