help n eed quick help on easy problem

need quick help how the heck do i set this up been at it for 4 hours now and nothing
1
2
3
4
5
 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.

    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.
Sounds like a homework, can I see your code first ?
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
#include <iostream>
#include <string>

using namespace std;

// Define the printmyname() function before main so we can define later
void printmyname(int times);

// Global Variable basically in this case
static string name;

int main()
{
	// Default Value for cntTimes
	bool startup = true;
	bool run = true;
	int cTimes = 0;

	// Initial Greeting
	printf("Hello, Please input a name: ");

	while (true)
	{
		if (run)
		{
			cin.clear(); // Clear the console input

			// To avoid using Hello again, we check to see if cntTimes is new
			if (!startup)
				cout << "\nNew Name: ";
			else startup = false;

			// Get the Name
			getline(cin, name);

			// Output the Chosen Name and ask how many times to repeat.
			printf("\n> The name chosen is: %s\nHow many times should I say your name? ",
				name.c_str()); // user c_str(); to make it readable in our output. %s to get the
			// string value from our name.c_str(); variable function.

			// Get number of repetition(s)
			if ((cin >> cTimes))
			{
				if (cTimes > 0 && cTimes <= 10)
				{
					printmyname(cTimes);
					cin.clear(); // Clear the console input
					cin.ignore(INT_MAX, '\n'); // Ignore until new line is input
				}
				else {
					cin.clear(); // Clear the console input
					cin.ignore(INT_MAX, '\n'); // Ignore until new line is input
					printf("> In this case it is not possible to print the name.\n");
					run = false;
					continue;
				}
			}
			else run = false;
		} 
		else if (!run)
		{
			// Temporary variable for holding answer
			char answer = 'a';

			// Ask user question
			printf("Would you like to try Again? [y/n]");

			// Get Answer from user
			cin >> answer;

			// Check the answer and take action accordingly
			if (answer == 'y' || answer == 'n')
			{
				if (answer == 'y')
				{
					run = true;
					cin.clear();
					cin.ignore(INT_MAX, '\n');
				}
				else return 0;
			}
			else return 0;
		}
	}
}

// Or Definition to printmyname() function
void printmyname(int times)
{
	for (int i = 0; i < times; ++i)
		cout << endl << (i + 1) << "> " << name;
}


Note that this code "Works" for the most part, really not optimal though, should be good for referencing and learning about new things though.
Last edited on
Seriously did you have make your own code ? Next time you should post your code so we know that you have tried to do it..
Here's the code that probably you want, sorry if there's any bug, I don't check it:
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>

void printmyname(int input);

int main()
{
    int input;
    std::cout << "Enter an integer: ";
    std::cin >> input; // For learning purpose and for the simple way please enter integer not any others
                  // if you want to make a program that show error if the user enter not integer go somewhere else,
                  // I'll not cover it here

        // Set integer between 0 - 10
        if ( input <= 0 || input > 10 )
            std::cout << "It is not possible to print the name. " << std::endl;
        else
            printmyname(input);

    return 0;
}

void printmyname(int input) {

    for (int i=0; i<input; i++)
    std::cout << "My name" << std::endl; // of course change My name into your name
}


Okay I'll post this for learning purposes next time remember to post your own code so we know to what extent you have mastering the topic, thus we can give the best help we could do.
Have a nice day...

Seriously did you have make your own code ? Next time you should post your code so we know that you have tried to do it..


Not sure what you're trying to imply by that, just thought it'd be nice to give him some sample code relative to his situation to help promote the learning process. Yes I did quickly come up with something and inserted notes to help understand what's going on.
Err,. That statement is not for you Peppercorn, it's for bbb718, I believe(very sure) this post is about his/her homework, so next time he/she must post his/her code first, so we(me and you peppercorn) know that bbb718 have tried to do his/her homework and not making us to do it instead...
Topic archived. No new replies allowed.