No Output

shattered space

Distinguished
Dec 18, 2010
26
0
18,580
0
OK. So I'm learning C++ on my own through online tutorials and online readings. There have been a few exercises that I've typed in and they should output a final number or a few numbers. This one exercise I just got sick and tired of trying to guess and check what is happening. Here's the code.


1. #include <iostream>
2. using namespace std;
3.
4. int main()
5. {
6. unsigned short shirts;
7. unsigned short pants;
8. unsigned short dresses;
9. unsigned short ties;
10.
11. cout << " -=- Georgetown Cleaning Services -=-\n";
12. cout << "Enter number of shirts: ";
13. cin >> shirts;
14.
15. cout << "Enter number of pants: ";
16. cin >> pants;
17.
18. cout << "Enter number of dresses: ";
19. cin >> dresses;
20.
21. cout << "Enter number of ties: ";
22. cin >> ties;
23.
24. cout << "\n====================================";
25. cout << "\n-=- Georgetown Cleaning Services -=-";
26. cout << "\n====================================";
27. cout << "\nCustomer Order"
28. << "\nItem Type Qty"
29. << "\nShirts: " << shirts
30. << "\nPants: " << pants
31. << "\nDresses: " << dresses
32. << "\nTies: " << ties
33. << "\n\n";
34.
35. return 0;
36. }

Why is it that from 24 - 32 is not being displayed for a continuous amount of time, until a press a button?
 

randomizer

Distinguished
Moderator
Jul 24, 2006
880
0
19,260
62

Because you haven't told it to. A program does exactly what you programmed it to do, and can't assume that you want it to sit and wait for you unless given the instruction to do so (it doesn't even know if a human is running it). This is the basic logic of your program:

1. Allocate memory to some variables.
2. Display some text on the standard output (console).
3. Get the user's input and store it in the specified variable.
4. Do steps 2. and 3. three more times.
5. Output a bunch of strings, including the values of several variables, to the console.
6. Return 0 (success) and exit.

What you need is something like cin.ignore() to make it wait. And whatever you've read, system("pause") is not the solution.
 

shattered space

Distinguished
Dec 18, 2010
26
0
18,580
0

I'm using Dev-C++ 4.9.9.2. No there weren't any warning, and I just started learning so I don't know what strict warnings are nor how to enable such.
 

theDanijel

Distinguished
May 4, 2011
74
0
18,590
3
I think he didn't express himself right. The program runs and then exits fast since there is nothing stoping it. Try adding in the 34. line "cin>>ties;" just to keep the console active.
 

PhilFrisbie

Distinguished
Apr 22, 2006
666
0
19,310
53

OK, I see that now ;)

Instead of double-clicking the console program, open up a command prompt an run it from there.
 

shattered space

Distinguished
Dec 18, 2010
26
0
18,580
0

I tried that but I would also like a way for the user to just press enter after seeing the output and when they press enter the program closes.
 
Thread starter Similar threads Forum Replies Date
P Apps General Discussion 2
A Apps General Discussion 5
clintox Apps General Discussion 3
T Apps General Discussion 1
R Apps General Discussion 2
O Apps General Discussion 1
I Apps General Discussion 2
Jmurph01 Apps General Discussion 1
Zaporro Apps General Discussion 1
K Apps General Discussion 4
K Apps General Discussion 1
Q Apps General Discussion 2
Can You Help Me Please Apps General Discussion 1
H Apps General Discussion 3
M Apps General Discussion 1
K Apps General Discussion 2
deadshots Apps General Discussion 7
S Apps General Discussion 2
A Apps General Discussion 5
G Apps General Discussion 2

ASK THE COMMUNITY

TRENDING THREADS