array char[] error :(

Hi guys, i have a problems understanding about array char but it was required in my code to have a array char named outcome with size 15.
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
class Check
{
  char outcome[15];
  collection[3];
public:
  void getCollection()
  {
    for (int i=0; i<3; i++)
    { 
      cout << "Enter collection: ";
      cin >> collection[i];
    }
  void calculate()
  { 
    float total = collection[0]+collection[1]+collection[2];
    getOutcome(total, outcome);
  }
  void getOutcome(float t, char& arg[])
  {
    if(total>=10)
      arg = "High";
    else
      arg = "Low";
  }
  void display()
  {
    for (int i=0; i<3; i++)
      cout << "collection : " << collection[i];
    cout << "outcome : " << outcome;
};
    
main ()
{
  Check k;
  k.getColection();
  k.calculateCollection();
  k.display();
}

the class method and private members are all given, i just need to implement it ... so i cant change it..
but the "outcome" came out as rubbish value..
and sometimes there is an error saying total not declared.. or reference const char[] to char[] which i tried using strcpy(outcome, "High") but it is still rubbish value.. Please help :')
Last edited on
The code above doesn't compile, there are numerous errors - missing closing braces, collection[3] declared without a type, wrong names used in main ... etc.

So it doesn't give any output at present.

Function getOutcome() could be written like this:

1
2
3
4
5
6
7
  void getOutcome(float t, char arg[])
  {
    if (t >= 10)
        strcpy(arg, "High");
    else
        strcpy(arg, "Low");
  }



Or perhaps like this:
1
2
3
4
5
6
7
  void getOutcome(float t)
  {
    if (t >= 10)
        strcpy(outcome, "High");
    else
        strcpy(outcome, "Low");
  }


Topic archived. No new replies allowed.