Sign in with
Sign up | Sign in
Your question

No Output

Last response: in Applications
Share
March 3, 2012 3:20:34 AM

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?

More about : output

a b L Programming
March 3, 2012 4:04:43 AM

What compiler are you using?
Were there any compiler warnings? If not, have you tried to enable strict warnings?
m
0
l
a b L Programming
March 3, 2012 10:00:36 AM

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

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.
m
0
l
Related resources
March 4, 2012 11:06:53 PM

PhilFrisbie said:
What compiler are you using?
Were there any compiler warnings? If not, have you tried to enable strict warnings?

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.
m
0
l
March 5, 2012 12:40:35 PM

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.
m
0
l
a b L Programming
March 5, 2012 6:13:34 PM

theDanijel said:
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.

OK, I see that now ;) 

Instead of double-clicking the console program, open up a command prompt an run it from there.
m
0
l
March 6, 2012 8:15:40 PM

theDanijel said:
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.

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.
m
0
l
!