×

注意!页面内容来自https://cplusplus.com/forum/beginner/142274/,本站不储存任何内容,为了更好的阅读体验进行在线解析,若有广告出现,请及时反馈。若您觉得侵犯了您的利益,请通知我们进行删除,然后访问 原网页

 
How to insert a blank line

Sounds really dumb and simplebut I can't figure out how to create a space between certain lines. Here's the code,

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

#include <iomanip>

using namespace std;



int main()

{

    // Variables

    double meal_costtaxtiptotal_cost;



    // Set output for number formatting

    cout << setprecision(2) << fixed << showpoint;



    // Welcome Message

    cout << "WELCOME TO THE BROWARD CAFE!!!\n"; 



    // Ask the user to input the cost of the meal.

    cout << "Please enter the total cost of the meal:";

    cin >> meal_cost;



    // Calculate the tax amountthe tip amount and the total cost of the meal.

    meal_cost = meal_cost;

    tax =  meal_cost * 0.07;

    tip = meal_cost * 0.20;

    total_cost = meal_cost + tax + tip;

       

    // Display the calculated data.

    cout << "Meal Cost: $" << meal_cost << endl;

    cout << "Tax: $" << tax << endl;

    cout << "Tip: $" << tip << endl;

    cout << "Total Cost: $" << total_cost << endl;

    return 0;

}

Everything runs fine and it calculates what I wantI just need it to look like this with the space between "Please enter...meal" and "Meal Cost"

WELCOME TO BROWARD CAFÉ!!
Please enter the total cost of the meal: $_40_

Meal Cost: $40.00
Tax: $2.80
Tip: $8.00
Total Cost: $50.80

instead of what it currently looks like...

WELCOME TO BROWARD CAFÉ!!
Please enter the total cost of the meal: $_40_
Meal Cost: $40.00
Tax: $2.80
Tip: $8.00
Total Cost: $50.80
Print another '\n' or endl before you print the calculated databut after you receive input.
I'm not sure exactly where to insert itcan I do it where the calculations occur?
insert it any where you want. You can experiment with it until you have what you want.
cout << endl;

or "\n" inside a text string like:

cout << "This is a \n new line " << endl; <---- edl also adds a new line

or : add another endl after endl like this :

1
2
3
4
5
6
7
cout << "Meal Cost: $" << meal_cost << endl << endl;

    cout << "Tax: $" << tax << endl << endl;

    cout << "Tip: $" << tip << endl << endl;

    cout << "Total Cost: $" << total_cost << endl << endl;



Sorry didn't read your whole post but you get the idea and now you should be able to format it the way you want...
Last edited on
Topic archived. No new replies allowed.