Need help please

Mar 14, 2017 at 10:20pm
Can't figure out how to do the last part of the paragraph:

The main program will call a function named printmyname(), sending it one parameter -- the sum of the integer values. The function will print your name that many times, and the function will not return a value. (Be careful – see below.)

For example, if the parameter to the function is 2, then the function should print your name 2 times. If the parameter is 4, the function should print your name 4 times.

**** THIS PART ----> However, if the parameter sent in is less than or equal to 0, or if the parameter sent in is greater than 10, the function will say it is not possible to print the name. For example, if the parameter is -2, the function will say in this case it is not possible to print the name. If the parameter is 12, the function will say it is not possible to print the name.****


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

using namespace std;

void introduction();

void printmyname(int sum);

int findsum (int,int,int);

int main()
{
    int x, y, z, printsum;

introduction();
cout<<endl;

cout <<"Please enter 3 integers, positive, negative, or zero."<<endl;
cin>>x>>y>>z;


printsum=findsum(x,y,z);

cout<<printsum<<endl;


printmyname(printsum);


}

void introduction()
{
    cout<<"test";
}


int findsum(int a,int b,int c)
{
    int sum;


    if ( a < b )
    {
        int temp = a; a = b; b = temp;
    }



    if ( b < c )
    {
        int temp = b; b = c; c = temp;
     }

    sum =( a + b );

    return sum;

}


void printmyname(int sum){

    if(sum>10 && sum<=0)
    {
        cout<<"it is not possible to print the name in this case";

    else

    int x;
    for(x=1; x<=sum; x++)
    cout<<"Bob"<<endl;
    }


                        }




}
Mar 14, 2017 at 10:29pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Brackets are out of place.
void printmyname(int sum){
    // Should be ||. Can't have a number that's both greater than 100 AND less than or equal to 0
    if(sum>10 && sum<=0) 
    {
        cout<<"it is not possible to print the name in this case";

    else

    int x;
    for(x=1; x<=sum; x++)
    cout<<"Bob"<<endl;
    }


                        }
Last edited on Mar 14, 2017 at 10:31pm
Mar 14, 2017 at 11:27pm
I've adjusted the brackets and I'm getting an error.

void printmyname(int sum){

if(sum>10 || sum<=0)
{
cout<<"it is not possible to print the name in this case";
}
else
{



int x;
for(x=1; x<=sum; x++)
cout<<"Bob"<<endl;
}


}






return 0;
}
Mar 14, 2017 at 11:28pm
There's no point of the return 0; and the }
Mar 14, 2017 at 11:48pm
Got it! Thank you so much!

I need to get more sleep :-)
Topic archived. No new replies allowed.