console not displaying every character I type

I am inputting in the console but as I type the number I can only see the first character. If I typed 345 on the 3 would show in the console. The calculations are being performed by the code and outputted correctly.

How do I change settings for the console?

all of my variables are double. Should I make some thing a float, int, or something else. Eventually, I have to calculate percentage of correct answers so I need something with a precision of at least 2 places after the decimal.

Thanks
What are you using to capture user input ?
The assignment is to build a program that will help elementary student practice multiplication. The randomly generated numbers to multiply sometimes produce a product with two digits. When I enter the two digits in my console only the first one is visible. The calculations are still performed by the program though.

Here is my code. I am using Xcode.


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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <ctime>
#include <cmath>
#include <fstream>
using namespace std;

//#include "GradeBook.h"
//int argc, const char * argv[]
int main(int argc, const char * argv[])
{
    double correctAnswer = 0;
    double incorrectAnswer = 0;
    double percentCorrect;
    
    
        for(int counter = 1; counter<=5; counter++)
        {
            srand( (unsigned)time(0) );//randomize the randomizer with time as the seed
            double x = rand()  % 9 +1;//randomly generated number between 1 and 10
            double y = rand() % 9 +1;//randomly generated number between 1 and 10
            
            

            double product = x * y;//the correct answer
            double answer;//student's answer input
           
            
            
            cout << "What is " << x << " times " << y << "?" << endl;//prompt user for mulitplication answer to randomly generated problem
            
            
            cin >> answer;//users answer to be checked and compared with computer's product
            if (answer == product)//checking to see correctness of user's answer
            {
                ++correctAnswer;
                int goodStatement = rand()  % 3 +1;
                switch (goodStatement)
                {
                    case 1:
                        puts("Very good!");
                        break;
                    case 2:
                        puts("Excellent");
                        break;
                    case 3:
                        puts("Nice work!");
                        break;
                    case 4:
                        puts("Keep up the good work");
                        break;
                        
                    default:
                        puts("Default good");
                        break;
                }

            }
            
            else
                
                
            while (answer!= product)
            {//while loop shall run with the same x and y values being presented. The program will not move forward until a correct answer is entered by user.
                ++incorrectAnswer;
                int badStatement = rand()  % 3 +1;
                switch (badStatement)
                {
                    case 1:
                        puts("No. Please try again");
                        break;
                    case 2:
                        puts("Wrong. Try once more");
                        break;
                    case 3:
                        puts("Don't give up");
                        break;
                    case 4:
                        puts("No. Keep trying");
                        break;
                    default:
                        puts("This is the default no");
                        break;
                }

                cout << "What is " << x << " times " << y << "?" << endl;
                cin >> answer;
            
                if (answer == product)//checking to see correctness of user's answer
                {
                ++correctAnswer;
                int goodStatement = rand()  % 3 +1;
                switch (goodStatement)
                {
                    case 1:
                        puts("Very good!");
                        break;
                    case 2:
                        puts("Excellent");
                        break;
                    case 3:
                        puts("Nice work!");
                        break;
                    case 4:
                        puts("Keep up the good work");
                        break;
                        
                    default:
                        puts("Default good");
                        break;
                }       
        
                }
            }
            
            
        }
    
            cout << "You got " << correctAnswer <<" of them correct. Great work!" << endl;
            cout << "You missed " << incorrectAnswer << "." << endl;
    
            percentCorrect = (correctAnswer / correctAnswer + incorrectAnswer)*100;
            cout << percentCorrect << (setprecision(2)) << "%" << endl;
    if (percentCorrect < .75) {
        cout << "Please ask you teacher for extra help." << endl;       
    } else {
        cout << "Congratulations, you are ready to go t the next level!" << endl;
    }
    
   
       

}
I don't see anything that'll cause this behavior here...
Does this work with multi digits ?
1
2
3
4
5
6
7
8
9
#include <iostream>
int main()
{
double x;
cin >> x;
cout << x;
system("PAUSE");
return 0;
}

You also have some includes there that are probably not necessary...
Last edited on
This may not be related to your problem, but there are problems comparing doubles like you have. Floating point is stored as a binary fraction - not all numbers can be represented exactly. This always fails:

1
2
float a = 0.1;  //a == 0.09999997
if (10 * a == 1.0)  //fail == 0.99999997 


changing the type to double doesn't help, still the same type of problem.

You can use numeric_limits<double>epsilon. Google to find out how to use it. Also look at the reference page at the top left of this page.

HTH
@soranz

I tried what you posted and no it did not work. I can still only see one input character. The out put is fine. it printed 7 or 8 characters or a number in scientific notation.

I am starting to think that it is not my code but a setting or preference in Xcode.

hmmm.

-Josh
Yes, it must be some outside setting either in Xcode or the console but I can't think of what...
The same thing happens for me, however I have noticed that if you switch the output drop down to "Target" or "All" after you compile the program, the proper numbers will show up.
@Jack Kearl

Hey thanks for the reply. I did try your trick but it still didn't work for me. It is not a show stopper but darned close.

I have a tutor coming by this week so hopefully he has some experience with it and I'll post the solution if I've found one.

-Josh.
I have similar problem. This is possibly an XCode 4.5 bug, if you're using 4.5
Here is a self-explanatory discussion of the problem:
https://discussions.apple.com/thread/4318031?start=0&tstart=0
Thanks gkorablev,

That makes me feel a little better that the problem is not with my machine. I have bookmarked the forum post on Apple's communities that you sent us. I will be eagerly waiting for that update.

-Josh
It looks like Apple just released a bug fix for this. Yay. 03Oct2012.

"It looks like all our troubles are over"
-Walter Sobchek
Apple ? Well, they're not perfect either. lol
Topic archived. No new replies allowed.