clear

how do you remove movie name:, adult ticket sold? and child ticket sold? from the output? when you run this code i use those to gather information.
so i need the bottom part just for the output not the part before it

movie name:death grip
adult tickets sold?234
child tickets sold?123

Movie Name: "death grip"
Adult Tickets Sold: 234
Child Tickets Sold: 123
Gross Box Office Profit: $ 1773.00
Net Box office Profit: $ 354.60
Amount Paid to Distributor: $ 1418.40


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
  #include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;


int
main ()
{

  string movieName;
  int noOfAdultTicketSold;
  int noOfChildTicketSold;
  const double AdultTicFee = 6;
  const double ChildTicFee = 3;


  cout << "movie name:";
  getline (cin, movieName);
  cout << "adult tickets sold?";
  cin >> noOfAdultTicketSold;
   if (cin.fail ())
    {
      cout << endl << "Number of adults must be a number." << endl;
      exit (0);
    }
  cout << "child tickets sold?";
  cin >> noOfChildTicketSold;
   if (cin.fail ())
    {
      cout << endl << "Number of children must be a number." << endl;
      exit (0);
    }

  cout << setw (30) << left << "Movie Name:" << "\"" << movieName << "\"" <<
    endl;
    
  cout << setw (33) << left << "Adult Tickets Sold:" << noOfAdultTicketSold;
  cout << setw (5) << "" << endl;
 

  cout << setw (33) << left << "Child Tickets Sold:" << noOfChildTicketSold;
  cout << setw (5) << "" << endl;


 
  double TotalTake =
    AdultTicFee * noOfAdultTicketSold + noOfChildTicketSold * ChildTicFee;

  cout << setw (30) << left << "Gross Box Office Profit: " << "$  " <<
    setw (7) << right << fixed << setprecision (2) << TotalTake << endl;

  double NetBoxofficeProfit = TotalTake * 0.2;

  cout << setw (30) << left << "Net Box office Profit: " << "$  " << setw (7)
    << right << NetBoxofficeProfit << endl;

  double AmountPaidtoDistributor = TotalTake - NetBoxofficeProfit;

  cout << setw (30) << left << "Amount Paid to Distributor: " << "$  " <<
    setw (7) << right << AmountPaidtoDistributor << endl;


  return 0;
}
Hello poonamp6792,

The first three line you see on the screen come from your input prompts.

If you do not want these line in your final output there are several options.

First you could re position the cursor to the first line and output over what is there.

Second re position the cursor to the first line and print a long line of spaces to remove what is there, Re position the cursor again then do your final output.

Third make your input prompts look like you final output and use them as input prompts and final output adding the extra line for final output.

Forth you could use a function to clear the screen. I would stay away from anything that starts with "system" as it could leave your program vulnerable to attack. Also trying to clear the screen or re position the cursor is generally tied to the operating system you are using and may not work for everyone.

I use a function to clear the screen, but it is designed for windows. Let me know if you are interested. You could also try reading http://www.cplusplus.com/forum/beginner/1988/ for some ideas. Or do a search here on "clear screen" and see what comes up. You should find something useful.

As a last note the if statements t lines 23 and 30. If this i what you want I would add a pause before the exit so the user ha a chance to read the message before the program exits and the window closes. And I would suggest for line 26 use "exit(1)" and line 33 use "exit(2)". This will give you the information needed to know which input caused the problem. "exit(0)" can be used, but zero means that the program ended normally which it did not.

Let me know what you would like to do and I will help you figure it out.

Hope that helps,

Andy
thanks andy !

i wanted to use a function to clear the screen. i tried system before i posted here and it didnt seem to work well with pico as thats what im using for doing this coding.

and im using ubuntu linux for terminal
and also i tried to use pause for the cin fails but i dont think it worked correctly it shows error message
Topic archived. No new replies allowed.