Need help with void function please!

Ultimately, I am trying to get this to display a rocket using the void function making two triangles and three rectangles using the "*" character but I can't seem to get the void triangle to work. I am getting a invalid function declaration, does anyone have an idea to help me fix this so that I can get this to output correctly?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<cmath>
#include<string>
#include <iostream>

using namespace std;
void triangle;

int main()
{
    triangle;
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

void triangle
{

cout <<"  *   "<<endl;
cout <<" * *  "<<endl;
cout <<"*   * "<<endl;
}
closed account (1v5E3TCk)
it must be like that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<cmath>
#include<string>
#include <iostream>

using namespace std;
void triangle();

int main()
{
    triangle();
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

void triangle()
{

cout <<"  *   "<<endl;
cout <<" * *  "<<endl;
cout <<"*   * "<<endl;
}


dont forget to put "()" after the name of function when you declare, define or call it
Last edited on
In both line 10 and line 16, write () after triangle.
Thanks guys! I may post again later if I have anymore trouble finishing it
Ok, I am stumped now.. For the second part of this program I have to ask the user to enter in a symbol to make a second rocket, and I will show you what I have so far... It came up with a bunch of errors that I can't figure out at all. If anyone could help me out it would be extremely appreciated. Thank you here is my code:

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
#include<cmath>
#include<string>
#include <iostream>

using namespace std;
void triangle();
void rectangle();
void rocket(char);

int main()
{
    triangle();
    rectangle();
    rectangle();
    rectangle();
    triangle();
    
    char sym;
    
    cout<<"Enter in a symbol: "<<;
    cin>>sym>>;
    
    rocket(sym);
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

void triangle()
{

cout <<"  *   "<<endl;
cout <<" * *  "<<endl;
cout <<"*   * "<<endl;
}

void rectangle()
{
cout <<"*****"<<endl;
cout <<"*   *"<<endl;
cout <<"*   *"<<endl;
cout <<"*****"<<endl;
}

void rocket(char sym)
{
     cout << "3-2-1-Blast off!! " << sym << endl;
     
     cout <<  sym   <<endl;
     cout << sym<< sym<<  <<endl;
     cout <<sym<<   sym<< <<endl;
     cout <<sym<<sym<<sym<<sym<<sym<<endl;
     cout <<sym<<   <<sym<<endl;
     cout <<sym<<   <<sym<<endl;
     cout <<sym<<sym<<sym<<sym<<sym<<endl;
     cout <<sym<<sym<<sym<<sym<<sym<<endl;
     cout <<sym<<   <<sym<<endl;
     cout <<sym<<   <<sym<<endl;
     cout <<sym<<sym<<sym<<sym<<sym<<endl;
     cout <<sym<<sym<<sym<<sym<<sym<<endl;
     cout <<sym<<   <<sym<<endl;
     cout <<sym<<   <<sym<<endl;
     cout <<sym<<sym<<sym<<sym<<sym<<endl;
     cout <<  sym   <<endl;
     cout << sym<< sym<<  <<endl;
     cout <<sym<<   sym<< <<endl;
}     
Last edited on
hey, seems like you don't quiet understand the concept of functions, here take a quick look at this tutorial:
http://www.cprogramming.com/tutorial/lesson4.html

bye :)
Last edited on
There are lots of errors in the cin and cout statements.

In main(),
1
2
    cout<<"Enter in a symbol: "<<;
    cin>>sym>>;


should be:
1
2
    cout<<"Enter in a symbol: ";
    cin>>sym;


Further down the code there are lines like this:
 
     cout <<sym<<   sym<< <<endl;

there, you are asking the program to output something, but didn't specify what:
 
     cout <<sym<<   sym<< "what do you want here?" <<endl;

If you want a space, then put ' ',
or if you want several spaces, then put "      " etc.
Thanks, I found where a lot of my errors were. I got everything simplified down to just one error in line 21.. It says it expected a primary expression before ";" in line 21. Does anyone see where I went wrong with this now?

Thanks again

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
#include<cmath>
#include<string>
#include <iostream>

using namespace std;
void triangle();
void rectangle();
void rocket(char);

int main()
{
    triangle();
    rectangle();
    rectangle();
    rectangle();
    triangle();
    
    char sym;
    
    cout<<"Enter in a symbol: ";
    cin>>sym>>;
    
    rocket(sym);
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

void triangle()
{

cout <<"  *   "<<endl;
cout <<" * *  "<<endl;
cout <<"*   * "<<endl;
}

void rectangle()
{
cout <<"*****"<<endl;
cout <<"*   *"<<endl;
cout <<"*   *"<<endl;
cout <<"*****"<<endl;
}

void rocket(char sym)
{
     cout << "3-2-1-Blast off!! " << sym << endl;
     
     cout <<sym<<endl;
     cout <<sym<<sym<<endl;
     cout <<sym<<sym<<endl;
     cout <<sym<<sym<<sym<<sym<<sym<<endl;
     cout <<sym<<sym<<endl;
     cout <<sym<<sym<<endl;
     cout <<sym<<sym<<sym<<sym<<sym<<endl;
     cout <<sym<<sym<<sym<<sym<<sym<<endl;
     cout <<sym<<sym<<endl;
     cout <<sym<<sym<<endl;
     cout <<sym<<sym<<sym<<sym<<sym<<endl;
     cout <<sym<<sym<<sym<<sym<<sym<<endl;
     cout <<sym<<sym<<endl;
     cout <<sym<<sym<<endl;
     cout <<sym<<sym<<sym<<sym<<sym<<endl;
     cout <<sym<<endl;
     cout <<sym<<sym<<endl;
     cout <<sym<<sym<<endl;
}     
Line 21 I covered in my previous post, but here it is again:
 
  cin>>sym>>;

Change to:
 
  cin>>sym;
Use whatever character you want :)
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
#include<iostream>
#include<iomanip>
using namespace std;
void triangle(char);
void rectangle(char);
int main()
{
char sym;
cout<<"Enter in a symbol: ";
cin>>sym;
triangle(sym);
rectangle(sym);
rectangle(sym);
rectangle(sym);
triangle(sym);
return 0;
}
void triangle(char s)
{
int x=3;
cout<<setw(x)<<s<<endl;
    for(int i=1;i<x;i++)
    {
        cout<<setw(x-i)<<s;
        cout<<setw(i*2)<<s<<endl;
    }
}
void rectangle(char s)
{
    for(int a=0;a<5;a++)
    cout<<s;
    for(int b=0;b<2;b++)
    cout<<endl<<s<<setw(4)<<s;
    cout<<endl;
    for(int c=0;c<5;c++)
    cout<<s;
    cout<<endl;
}
Topic archived. No new replies allowed.