Unknown error

This code gives me an error.
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
 #include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <time.h>
using namespace std;









/**
Variabilele de sistem
*/
int factor=9;
int speed=1;
int lungimea=108;/// Defaullt 108 sau 79 MAX 108
int folsopts=1; ///Folositi caracterele de mai jos
string cara[2];
cara[0]='/';
cara[1]='\\';
/**
Modificati in voie
*/






void scps(int i)
{
    int o=0;
    while(o<i)
    {
        cout<<" ";
        o++;
    }
}
void show1()
{
    int i=lungimea;
    while(i>0)
    {
        scps(i);
        if(folsopts==0)
        {
            cout<<'/'<<endl;
        }
       if(folsopts==1)
       {
            cout<<cara[0];
       }
        Sleep(speed);
        i-=factor;
    }
}
void show2()
{
    int i=0;
    while(i<lungimea)
    {
        scps(i);
        if(folsopts==0)
        {
            cout<<'\\'<<endl;
        }
        if(folsopts==1)
        {
            cout<<cara[1];
        }
        Sleep(speed);
        i+=factor;
    }
}
int main()
{
    int var=1;
    while(2)
    {

        switch(var)
        {
        case 1:
        {
            var=0;
            show1();
            break;
        }
        case 0:

        {
            var=1;
            show2();
        }

        }

    }
    return 0;
}

The error is "cara does not name a type"! How can this be solved?
Thank you!
I need help with just that error.
The code is supposed to make a spiral
Lines 3-4: The correct headers are <cstdlib> and <ctime>

Line 22: You need to include the <string> header if you're going to use strings.

Lines 23-24: These are executable statements. Executable statements can only exist inside a function. Move these lines to line 80.
Last edited on
Change
1
2
3
string cara[2];
cara[0]='/';
cara[1]='\\';
to
 
const char cara[2] = { '/', '\\' };



Topic archived. No new replies allowed.