Help with making output skip a line

Feb 12, 2017 at 9:44pm
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
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
	double const adultTicket = 6.00, childTicket = 3.00;

	double grossProf, boxProf, distributor, adultSales, childSales; 

	int adult, child;

	string movieName;
	
	cout << "What is the name of the movie? ";

	getline(cin, movieName);

	cout << "\nyou entered "<<movieName<<endl;

	cout << "\nHow many adult tickets were sold? ";

	cin >> adult;

	cout << "\nHow many child tickets were sold? ";

	cin >> child;
	
	adultSales = adultTicket*adult;

	childSales = childTicket*child;

	grossProf = childSales+adultSales;

	boxProf = grossProf*.20;

	distributor = grossProf*.80;
	
	cout << fixed<<setprecision(2);

	cout << "\nGross Box Office Profit: "<<grossProf;

	cout << "\nAmount Paid to Distributor: "<<distributor;

	cout << "\nNet Box Office Profit: "<<boxProf;
	
	
	return 0;
}


The part of my code that isn't skipping a line is:

1
2
3
4
5
6
7
	cout << fixed<<setprecision(2);

	cout << "\nGross Box Office Profit: "<<grossProf;

	cout << "\nAmount Paid to Distributor: "<<distributor;

	cout << "\nNet Box Office Profit: "<<boxProf;


Even though I have "\n" it won't skip but if I put:

 
cout << "\n\nNet Box Office Profit: "<<boxProf;


with the two "\n" then it does skip a line. Why is that? I suppose I could just do that but it looks a little strange and more of a cop out. If there's a more correct way of having it skip a line I would prefer to learn it.

Thanks for the help!
Last edited on Feb 12, 2017 at 9:51pm
Feb 12, 2017 at 11:46pm
I think it would make more sense if you add the newline character to the end of the string rather than at the front.
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
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    double const adultTicket = 6.00, childTicket = 3.00;

    double grossProf, boxProf, distributor, adultSales, childSales; 

    int adult, child;

    string movieName;
    
    cout << "What is the name of the movie? ";

    getline(cin, movieName);

    cout << "You entered " << movieName << "\n\n";

    cout << "How many adult tickets were sold? ";
    cin >> adult;

    cout << '\n';

    cout << "How many child tickets were sold? ";
    cin >> child;
    cout << '\n';
    
    adultSales = adultTicket*adult;

    childSales = childTicket*child;

    grossProf = childSales+adultSales;

    boxProf = grossProf*.20;

    distributor = grossProf*.80;
    
    cout << fixed <<setprecision(2);

    cout << "Gross Box Office Profit: " << grossProf << '\n';

    cout << "Amount Paid to Distributor: " << distributor << "\n\n";

    cout << "Net Box Office Profit: " << boxProf << '\n';
    
    
    return 0;
}


What is the name of the movie? a
You entered a

How many adult tickets were sold? 1

How many child tickets were sold? 1

Gross Box Office Profit: 9.00
Amount Paid to Distributor: 7.20

Net Box Office Profit: 1.80


A newline character simulates an enter key press (to some extent). A single newline character doesn't leave a blank line after your output. You would need two newline characters to do that.
Last edited on Feb 12, 2017 at 11:46pm
Feb 13, 2017 at 6:57pm
Ah, I see I just always assumed that when a newline character was used that it would skip a line. I appreciate the assistance, integralfx
Last edited on Feb 13, 2017 at 6:59pm
Topic archived. No new replies allowed.