Program flow (skipping?)

I've ran across this problem a couple of different times now and was wondering if anyone could help me out a bit

After entering the amounts, it asks for which month to review (this is were the problems start) After entering the month it goes blank, (it is asking for y/n) actually I'm not sure whats going its a mess =/ thanks

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

const int NUM=3;

void main()
{
float sales[NUM];
int ctr, ans;
int month;

//Fill array
cout<<"Enter monthly sales \n";
for (ctr = 0; ctr < NUM; ctr++)
{
	cout<<"Month "<<ctr+1<<"?\n";
	cin>>sales[ctr];
}

// wait for request month
for(ctr=0; ctr<25; ctr++){cout<<"\n";}

cout<<"******Sale Printing Program*******\n";
cout<<"Prints any sales from the last "<<NUM<<" Months\n\n";

do
{
	cout<<"What month (1-"<<NUM<<") would you like to see?";
	cin>>month;

//Adjust for zero-based subscript
	cout<<"\nMonth "<<month<<"'s sales are "<<sales[month-1];
	cout<<"\nContinue y/n?\n";
	ans = getch(); 
	ans=toupper(ans);
}while(ans == 'Y');

return ;
}


Last edited on
Try changing the ans variable to type char.

~psault
lol thanks I should of seen that b4 still not right tho.

after it gets to here:
cout<<"What month (1-"<<NUM<<") would you like to see?";
cin>>month;

it skips
cout<<"\nMonth "<<month<<"'s sales are "<<sales[month-1];
cout<<"\nContinue y/n?\n";

and goes straight to
ans = getch();

it then goes back to
cout<<"\nMonth "<<month<<"'s sales are "<<sales[month-1];
cout<<"\nContinue y/n?\n";
cout<<"What month (1-"<<NUM<<") would you like to see?";
cin>>month;


Got it! use "cin>>ans;" instead of "ans = getch()" But still dunno why the above don't work.





Last edited on
Topic archived. No new replies allowed.