1. ## getchar

The following is code for a VERY SIMPLE help menu

Code:
```//help.h

#include <iostream>

using namespace std;

void help(void){

int hop;

cout<<"Type 1 for simple calc help\nType 2 for root calc help\nType 3 for powers help\nType 4 for circumference\nType 5 for equation help\nType 6 for vector help:\n";

cin>>hop;

if(hop==1){

cout<<"Enter a simple problem, such as 4+7.8\nYou can use decimals or integers\nYou can use +-/* as functions\n";

}else if(hop==2){

cout<<"Select an option of which root\nEnter a number\nYou will recieve an approximate root\n";

}else if(hop==3){

cout<<"Enter a number and a power in the format x^y\nYou must include the ^ [carrot]\nYou recieve x to y power\n";

}else if(hop==4){

cout<<"Enter a number (r)\nYou receive the circumference\n";

}else if(hop==5){

cout<<"Enter an equation of one of the following formats:\n\nax+b=c\nc=ax+b\nb+ax=c\nax=c\nx+b=c\nc=x+b\nc=x+b\nc=ax\nc=b+ax/b=c+ax\nax=c+b/ax=b+c\nc+b=ax/b+c=ax\n";

}else if(hop==6){

cout<<"The program can return the sum/difference of two vectors\nThe product/quotient of a vector and a scalar\nOr the dot product of two vectors\n\n";
cout<<"Firstly you will be prompted to enter your first vector.\nAfter this, you will be prompted for a symbol.\n\n";
cout<<"You enter a symbol of + - * / or .\n\n";
cout<<"Depending on your symbol, you will be prompted for a vector or scalar\n\n";

}else{

cout<<"Invalid option\n";

}//end else/if

cout<<"Keep in mind, that due to the formatting of all numbers,\nall answers are APPROXIMATE\n";

getchar();

}//end void help```
Everything in there works, except for the very last (or second to last if you want to be picky about it) statement; getchar()

the program in question is being implemented on a MAC, so getchar() is the equivallent of the windows getch() or getche() and doesn't need to be included

for some reason, whenever I access the function in which getchar() is contained, it alwasy ignores the getchar() statement

This provides some considerable problems concerning the easy reading of the output

any ideas?

2. 1. dont use getchar as it is a c stand function which resides in stdio.h file ( in your code u need to include stdio.h file)

2. sometimes buffer would be containing some enter key left in there, need to ignore that from the buffer

u can use cin::ignore(10000,'\n')
3. and the most effective way to get a char in c++ is

Code:
```cin.ignore();
cin.get();```
replace this with the getchar in your code

regards
ssharish

3. getchar() does not do the same thing as getch(). I began my coding on a Mac, and had a similiar problem. I have some code that will emulate getch(), but I need to find it. I'll look for it and post if I can find it.

4. Code:
` cin>>hop;`
Code:
` getchar();`
getchar() is not being ignored. cin leaves the newline in the stream and getchar() successfully takes it out of the stream and thus passing program execution onto the next statement which exists the function.

You need 2 cin.get() statements, which is what you should be using considering this is C++.

5. cin skips all leading whitespace, then reads in data and stops reading in data when the first white space character is encountered(e.g. spaces, tabs, and newlines). The terminating whitespace character is left in the stream. This line:

cin>>hop;

waits for the user to enter data. Then, the user types something in and hits Return. Hitting Return enters an invisible \n after the input. So, if the user types in a 1 and hits Return, the input stream looks like this:

1\n

1) cin skips any leading whitespace--there's no whitespace in front of the 1, so
2) cin reads in the 1, and
3) cin stops reading when it encounters the whitespace character \n
4) cin leaves the \n in the input stream.

Then, further down in your program, this line is executed:

getchar();

which gets the next character out of the input stream. Since, there is a \n left in the input stream, getchar() doesn't need to wait for input and does it's thing and reads in the \n.

The lesson is: if you are going to be switching between cin and get() functions for reading in input, you need to remove the trailing whitespace that cin leaves in the stream. You can do that like this:

cin>>hop;
cin.ignore(1);

cin.ignore() will remove the designated number of characters from the stream. Note that cin.ignore() is not necessary if you do this:

cin>>hop;

and the user enters:

1\n

and then you do something like this:

cin>>hop2;

Since cin skips leading whitespace, cin skips over the \n looking for input, and since it can't find any, it waits for the user to enter something.