help me with formatting please! been trying to do it for hours and I can't get it. lol SoS

please help me with my homework, I am having trouble executing my code correctly . I managed to do everything properly except I'm not sure how to alternate between "*" and "-" as the sample output is asking its doing *'s and then -'s on every line. tried figuring this out for hours and still can't. probably simple. but I've been trying harder than needed. thanks in advance.

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
// Demonstrates passing arguments to function parameters.

#include <iostream>
#include <iomanip>
using namespace std;

// TODO: Write function prototype here. This function should be:
// Name: PrintLine
// Parameter(s): howMany & symbolToPrint (use appropriate data types)
// Returns: <nothing>

void PrintLine(int howMany, int symbolToPrint);



//-----------------------------------------------------------------------------

int main()
{
	/* TODO: Call (invoke) the function where necessary to
	produce output as shown in sample (below).

	NOTE: You will need to break-up this long output
	statement into at least 3 separate output statements.
	*/

	int howMany=0;
	int symbolToPrint=0;

	PrintLine(howMany, symbolToPrint);
	cout << endl;
	cout << "          Simple C++ Integer Types" << endl
		<< "            (Microsoft Specific)" << endl;
	PrintLine(howMany, symbolToPrint);
	cout << endl;
	cout << "Data type                Range" << endl;
	PrintLine(howMany, symbolToPrint);
	cout << endl;
	cout << "char: " << setw(20) << CHAR_MIN << " to " << CHAR_MAX << endl
		<< "short:" << setw(20) << SHRT_MIN << " to " << SHRT_MAX << endl
		<< "int:  " << setw(20) << INT_MIN << " to " << INT_MAX << endl
		<< "long: " << setw(20) << LONG_MIN << " to " << LONG_MAX << endl;
	PrintLine(howMany, symbolToPrint);
	cout << endl;
	return 0;
}

//-----------------------------------------------------------------------------

// TODO: Write the PrintLine function definition here
// Be sure that the function heading matches the prototype above
void PrintLine(int howMany, int symbolToPrint)
{
	for (int howMany = 1; howMany <= 45; howMany++)
	{
		cout << '*';
	}
	for (int symbolToPrint = 1; symbolToPrint <= 45; symbolToPrint++)
	{
		cout << '-';

	}
}
	// PrintLine()
	// prints symbolToPrint repeatedly (as defined by howMany) on one line




	//-----------------------------------------------------------------------------

	/*  Sample program output:

	*********************************************
	Simple C++ Integer Types
	(Microsoft Specific)
	----------------------------------------
	Data type                Range
	----------------------------------------
	char:                 -128 to 127
	short:              -32768 to 32767
	int:           -2147483648 to 2147483647
	long:          -2147483648 to 2147483647
	*********************************************

	*/
This should have been a separate program, to make sure you understood PrintLine.
1
2
3
4
5
6
7
8
9
10
11
void PrintLine(int howMany, char symbolToPrint) {
    for ( int i = 1 ; i <= howMany ; i++ ) {
        cout << symbolToPrint;
    }
    cout << endl;
}
int main ( ) {
    PrintLine(20,'*');
    PrintLine(30,'-');
    PrintLine(40,'=');
}

ok so I managed to make some progress with the coding after just checking back in. I found a way to make the * and - read but now im having trouble with writing the printline function definition as it keeps saying function void printline(int, char) already has a body. which I can see at the top but im trying to figure out why it asks for the pl function to be defined at the bottom when I already have at the beginning , I just tried anything / to change it hoping it would work in this example but it hasn't, please help me understand

#include <iostream>
#include <iomanip>
using namespace std;

// TODO: Write function prototype here. This function should be:
// Name: PrintLine
// Parameter(s): howMany & symbolToPrint (use appropriate data types)
// Returns: <nothing>
void PrintLine(int howMany, char symbolToPrint)
{
	for (int i = 1; i <= howMany; i++)
	{
		cout << symbolToPrint;
	}
	cout << endl;

}

//-----------------------------------------------------------------------------

int main()
{
	/* TODO: Call (invoke) the function where necessary to
	produce output as shown in sample (below).

	NOTE: You will need to break-up this long output
	statement into at least 3 separate output statements.
	*/

	PrintLine(45, '*');
	cout << " Simple C++ Integer Types" << endl;

	cout << " (Microsoft Specific)" << endl;
	PrintLine(40, '-');
	cout << "Data type Range" << endl;
	PrintLine(40, '-');
	cout << "char: " << setw(20) << CHAR_MIN << " to " << CHAR_MAX << endl;

	cout << "short:" << setw(20) << SHRT_MIN << " to " << SHRT_MAX << endl;

	cout << "int: " << setw(20) << INT_MIN << " to " << INT_MAX << endl;

	cout << "long: " << setw(20) << LONG_MIN << " to " << LONG_MAX << endl;
	PrintLine(45, '*');
	return 0;
}

//-----------------------------------------------------------------------------

// TODO: Write the PrintLine function definition here
// Be sure that the function heading matches the prototype above

void PrintLine(int n, char symbol) 
{
	for (int i = 0; i < n; i++) 
	{
		printf("%c", symbol);
	}
	printf("\n");
}
Last edited on
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
#include <iostream>
#include <iomanip>
#include <climits> // required for INT_MIN etc.
using namespace std;

// TODO: Write function prototype here. This function should be:
// Name: PrintLine
// Parameter(s): howMany & symbolToPrint (use appropriate data types)
// Returns: <nothing>
void PrintLine( int howMany, char symbolToPrint ) ;

//-----------------------------------------------------------------------------

int main()
{
	/* TODO: Call (invoke) the function where necessary to
	produce output as shown in sample (below).

	NOTE: You will need to break-up this long output
	statement into at least 3 separate output statements.
	*/
	cout << "Program 1: print a triangle\n" ;
    PrintLine( 40, '-' ) ;
    const int N = 6 ;
	for( int i = 0 ; i < N ; ++i ) PrintLine( i+1, '*' ) ;
	for( int i = 0 ; i < N ; ++i ) PrintLine( N-i-1, '*' ) ;

	cout << "\n\nProgram 2. Simple C++ Integer Types\n(Implementation Specific)\n" ;
	PrintLine( 40, '-' );
	cout << "Data type Range" << '\n';
	PrintLine( 40, '-' );

    cout << showpos ;

	cout << "     char: " << setw(20) << CHAR_MIN << "   to " << setw(20) << CHAR_MAX << '\n';

	cout << "    short: " << setw(20) << SHRT_MIN << "   to " << setw(20) << SHRT_MAX << '\n';

	cout << "      int: " << setw(20) << INT_MIN << "   to " << setw(20) << INT_MAX << '\n';

	cout << "     long: " << setw(20) << LONG_MIN << "   to " << setw(20) << LONG_MAX << '\n';

	cout << "long long: " << setw(20) << LLONG_MIN << "   to " << setw(20) << LLONG_MAX << '\n';

	PrintLine(45, '*');
}

//-----------------------------------------------------------------------------

// TODO: Write the PrintLine function definition here
// Be sure that the function heading matches the prototype above

void PrintLine(int n, char symbol)
{
	for( int i = 0; i < n; i++ ) cout << symbol ;
	cout << '\n' ;
}

https://rextester.com/ZFC58552
Last edited on
Topic archived. No new replies allowed.