How can i have 2 diffrent Functions in one program with void?

I want to print perimetros(4*p) and embadon(p*p).
I think that my problem is at the cout. Can anyone help me please ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

void perimetros(int p ){
    p=4*p;
    cout<<p<<endl;
}
void embado(int a ){
    a=a*a;
    cout<<a<<endl;
}
int main() {
   int p;
   cin>>p;
   cout<<perimetros(p)<<" " <<embado(a)<<endl;
    return 0;
}
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 <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

void perimetros(int p ){
    p=4*p;
    cout<<p<<endl;
}
void embado(int a ){
    a=a*a;
    cout<<a<<endl;
}
int main() {
   int p;
   cin>>p;
   perimetros(p);
   embado(p);
    return 0;
}
DDomjosa thank you very much I will try it ;)
It is useful when designing functions to have functions which do one thing, only. For instance, if you have a function that calculates the perimeter of a square, it should calculate and return the value to the calling code. It probably shouldn't print the value.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

int perimetros(int largo) {
    return 4 * largo;
}

int embado(int largo) {
    return largo * largo;
}

int main() {
    int lado;
    std:: cin >> lado;
    std::cout << perimetros(lado) << " " << embado(lado) << std::endl;
}
Topic archived. No new replies allowed.