Help me to make this program!

Hello Guys, Recently I have become keen towards programming stuff & i m a Ultimate noob in this, so i choose C++ and begin learning it on my own. As I was going through the programming exercises of Stephen Prata C++ primer book, I came across this question and i also tried to solve it but i m encountering errors.....Plz check the errors in the following code which I have written & Help to run the program correctly...
#thanks in Advance



Write a C++ program that uses three user-defined functions (counting main()as
one) and produces the following output:
Three blind mice
Three blind mice
See how they run
See how they run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include<iostream>
using namespace std;
void s1(void);
void s2(void);

int main()
{
    using namespace std;
    cout<< void s1();
    cout<<  void s2();

    return 0;


}
void s1(void m)
{
   return  cout<<"Three blind mice"<<endl;

}
void s2(void l)
{
  return   cout<<"See how they run"<<endl;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>

void s1(); //If function does not get parameters do not write them
void s2();

int main()
{
    s1(); //That is how you call functions
    s1();
    s2();
    s2();
}

void s1() //function does not get parameters
{
   std::cout << "Three blind mice\n"; //Your function is not returning anything
}

void s2()
{
    std::cout << "See how they run\n";
}
Last edited on
It should look like this:
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
#include<iostream>

using std::cout;

void s1 ( );
void s2 ( );

int main()
{
	s1 ( );
        s1 ( );
        s2 ( );
	s2 ( );

	return 0;
}

void s1 ( )
{
    cout << "Three blind mice\n";
}

void s2 ( )
{
	cout << "See how they run\n";
}


using namespace std; is discouraged due to various reasons. You also typed it twice.
You are only using cout from the std namespace, so you only need to do using std::cout;

You don't need to put void in your functions, it's void by default.
Since your functions are void, they should not be returning anything, yet you are attempting to return "cout<<"See how they run"<<endl;"

A note on endl: '\n' does essentially the same thing and is faster. Your code is small enough right now that you won't notice a difference, but you will with larger programs.

You cannot cout a void function as you are attempting to do in main.


Edit:
You should also use more descriptive names for your functions. I have no clue as to what s1 does unless I read the full function.
Last edited on
thanks MiiNiPaa &Yay295..

thanks Now I have understood the program completely and i have compiled it to without errors.....
Topic archived. No new replies allowed.