473,494 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with DO-WHILE Loop

Hello everyone. I am frustrated, I have written the simple program
below for a class and I am having problems with the DO-WHILE loop. On
the first run through the loop, everything works well, the menu is
displayed, the input is registered and the loop runs. On the second
(and following) runs the menu is printed twice. I am sure there is
something very basic that I am missing, but I cannot see it. Can
anyone help?

Thanks in advance.

Ken

****Here is the code****

/* currency.c - Version 1.2
This program receives a selection from the
user to determine the type of currency they
would like the exchange rate for. It then returns
the value of the amount of US currency they entered
in the currency type that they selected.*/

#include <stdio.h>

int main()
{
char nation; //Declare variable for the users choice of currencies

float us_dollar;
float canada_conv;
float euro_conv;
float krona_conv;
float yen_conv;
float pound_conv; //Declare variables of Float type

int cont = 0;

canada_conv = 1.2997; //Set exchange rates for all variables
euro_conv = 1.2056;
krona_conv = 7.5625;
yen_conv = 0.009057;
pound_conv = 0.7694;
us_dollar = 1.00; //set initial dollar amount

printf("Currency Conversion\n\n"); //Title of program

do {

cont = 0;

//Prompt user for currency
printf("Which currency would you like to convert?\n\n");
printf("Press 'C' for Canadian Dollars.\n");
printf("Press 'E' for Euros.\n");
printf("Press 'K' for Swedish Krona.\n");
printf("Press 'Y' for Japanese Yen.\n");
printf("Press 'P' for British Pounds.\n\n");
printf("Press 'Q' to quit.\n\n");

nation=getchar(); //Retrieves users choice and assigns "nation"
variable

switch (nation) //Selection process to give amount based on user
selection
{
case 'C':
case 'c':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Canadian Dollars.\n\n",
us_dollar, us_dollar * canada_conv);
cont = 0;
break;

case 'E':
case 'e':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Euros.\n", us_dollar, us_dollar
* euro_conv);
cont = 0;
break;

case 'K':
case 'k':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Swedish Krona.\n", us_dollar,
us_dollar * krona_conv);
cont = 0;
break;

case 'Y':
case 'y':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Japanese Yen.\n", us_dollar,
us_dollar * yen_conv);
cont = 0;
break;

case 'P':
case 'p':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f British Pounds.\n", us_dollar,
us_dollar * pound_conv);
cont = 0;
break;

case 'Q':
case 'q':
cont = 1;
printf("Thanks for using the Currency Conversion program.\n\n");
break;

default: //This is the error check. If the enter an incorrect
choice, they get shut down
break;
}

} while (cont!=1);
//Give user time to see results and end program
printf("\n\nPress any key and Enter to exit the program.\n");
scanf("%d");
return 0;
}
Nov 14 '05 #1
13 2165
Hello Ken,

You probably have "leftover characters" in the input buffer following the
call to scanf() - I've seen this before with progs that mix scanf() and
getchar(). Easiest solution, for this program, is not to mix them. Flushing
the buffer would probably work too, but I've not tried it.

Regards,
-Pete.

"Redduck" <ke**********@mail.com> wrote in message
news:ee*************************@posting.google.co m...
Hello everyone. I am frustrated, I have written the simple program
below for a class and I am having problems with the DO-WHILE loop. On
the first run through the loop, everything works well, the menu is
displayed, the input is registered and the loop runs. On the second
(and following) runs the menu is printed twice. I am sure there is
something very basic that I am missing, but I cannot see it. Can
anyone help?

Thanks in advance.

Ken

****Here is the code****

/* currency.c - Version 1.2
This program receives a selection from the
user to determine the type of currency they
would like the exchange rate for. It then returns
the value of the amount of US currency they entered
in the currency type that they selected.*/

#include <stdio.h>

int main()
{
char nation; //Declare variable for the users choice of currencies

float us_dollar;
float canada_conv;
float euro_conv;
float krona_conv;
float yen_conv;
float pound_conv; //Declare variables of Float type

int cont = 0;

canada_conv = 1.2997; //Set exchange rates for all variables
euro_conv = 1.2056;
krona_conv = 7.5625;
yen_conv = 0.009057;
pound_conv = 0.7694;
us_dollar = 1.00; //set initial dollar amount

printf("Currency Conversion\n\n"); //Title of program

do {

cont = 0;

//Prompt user for currency
printf("Which currency would you like to convert?\n\n");
printf("Press 'C' for Canadian Dollars.\n");
printf("Press 'E' for Euros.\n");
printf("Press 'K' for Swedish Krona.\n");
printf("Press 'Y' for Japanese Yen.\n");
printf("Press 'P' for British Pounds.\n\n");
printf("Press 'Q' to quit.\n\n");

nation=getchar(); //Retrieves users choice and assigns "nation"
variable

switch (nation) //Selection process to give amount based on user
selection
{
case 'C':
case 'c':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Canadian Dollars.\n\n",
us_dollar, us_dollar * canada_conv);
cont = 0;
break;

case 'E':
case 'e':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Euros.\n", us_dollar, us_dollar
* euro_conv);
cont = 0;
break;

case 'K':
case 'k':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Swedish Krona.\n", us_dollar,
us_dollar * krona_conv);
cont = 0;
break;

case 'Y':
case 'y':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Japanese Yen.\n", us_dollar,
us_dollar * yen_conv);
cont = 0;
break;

case 'P':
case 'p':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f British Pounds.\n", us_dollar,
us_dollar * pound_conv);
cont = 0;
break;

case 'Q':
case 'q':
cont = 1;
printf("Thanks for using the Currency Conversion program.\n\n");
break;

default: //This is the error check. If the enter an incorrect
choice, they get shut down
break;
}

} while (cont!=1);
//Give user time to see results and end program
printf("\n\nPress any key and Enter to exit the program.\n");
scanf("%d");
return 0;
}

Nov 14 '05 #2


Redduck wrote:
Hello everyone. I am frustrated, I have written the simple program
below for a class and I am having problems with the DO-WHILE loop. On
the first run through the loop, everything works well, the menu is
displayed, the input is registered and the loop runs. On the second
(and following) runs the menu is printed twice. I am sure there is
something very basic that I am missing, but I cannot see it. Can
anyone help?

Using function getchar leaves a '\n' char in stdin. A quick
fix would use function fgets in place of getchar. See below.
****Here is the code****

/* currency.c - Version 1.2
This program receives a selection from the
user to determine the type of currency they
would like the exchange rate for. It then returns
the value of the amount of US currency they entered
in the currency type that they selected.*/

#include <stdio.h>

int main()
{
char nation; //Declare variable for the users choice of currencies

make nation a char array, ie.
char nation[8];
float us_dollar;
float canada_conv;
float euro_conv;
float krona_conv;
float yen_conv;
float pound_conv; //Declare variables of Float type

int cont = 0;

canada_conv = 1.2997; //Set exchange rates for all variables
euro_conv = 1.2056;
krona_conv = 7.5625;
yen_conv = 0.009057;
pound_conv = 0.7694;
us_dollar = 1.00; //set initial dollar amount

printf("Currency Conversion\n\n"); //Title of program

do {

cont = 0;

//Prompt user for currency
printf("Which currency would you like to convert?\n\n");
printf("Press 'C' for Canadian Dollars.\n");
printf("Press 'E' for Euros.\n");
printf("Press 'K' for Swedish Krona.\n");
printf("Press 'Y' for Japanese Yen.\n");
printf("Press 'P' for British Pounds.\n\n");
printf("Press 'Q' to quit.\n\n");

nation=getchar(); //Retrieves users choice and assigns "nation"
variable
use fgets in place of getchar.

fgets(nation, sizeof nation, stdin);
switch (nation) //Selection process to give amount based on user
selection
switch(nation[0]);
{


........... snip .............
--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapidsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #3
Redduck wrote:

Hello everyone. I am frustrated, I have written the simple program
below for a class and I am having problems with the DO-WHILE loop. On
the first run through the loop, everything works well, the menu is
displayed, the input is registered and the loop runs. On the second
(and following) runs the menu is printed twice. I am sure there is
something very basic that I am missing, but I cannot see it. Can
anyone help?


.... snip code ...

As usual the problem is the use of scanf for interactive input.
Think about what is left in the input stream after executing that
call. Also think about other methods of getting the users input
which allow you to be sure of the input stream condition.

--
"It is not a question of staying the course, but of changing
the course" - John Kerry, 2004-09-20
"Ask any boat owner the eventual result of continuing the
present course indefinitely" - C.B. Falconer, 2004-09-20
Nov 14 '05 #4
The problem is of the clearence of the buffer:

Now when u enter the choice then after that u have to clear the buffer also.

As u know that *getchar* takes all the input into the buffer and then from
there it takes the value to the allocated mamory.

And the *getch* takes the each respective character and simultaneously stores
into the allocated memory. and once it over flows the memory sapsce a error
code is desplayed (this thing u have to handle manually)

So try to use the getch instead of getchar:

Or use the fflush function:

in this u will be handle the problem.

any way if u have the doubts then let me know.
Regards
Ranjeet

ke**********@mail.com (Redduck) wrote in message news:<ee*************************@posting.google.c om>...
Hello everyone. I am frustrated, I have written the simple program
below for a class and I am having problems with the DO-WHILE loop. On
the first run through the loop, everything works well, the menu is
displayed, the input is registered and the loop runs. On the second
(and following) runs the menu is printed twice. I am sure there is
something very basic that I am missing, but I cannot see it. Can
anyone help?

Thanks in advance.

Ken

****Here is the code****

/* currency.c - Version 1.2
This program receives a selection from the
user to determine the type of currency they
would like the exchange rate for. It then returns
the value of the amount of US currency they entered
in the currency type that they selected.*/

#include <stdio.h>

int main()
{
char nation; //Declare variable for the users choice of currencies

float us_dollar;
float canada_conv;
float euro_conv;
float krona_conv;
float yen_conv;
float pound_conv; //Declare variables of Float type

int cont = 0;

canada_conv = 1.2997; //Set exchange rates for all variables
euro_conv = 1.2056;
krona_conv = 7.5625;
yen_conv = 0.009057;
pound_conv = 0.7694;
us_dollar = 1.00; //set initial dollar amount

printf("Currency Conversion\n\n"); //Title of program

do {

cont = 0;

//Prompt user for currency
printf("Which currency would you like to convert?\n\n");
printf("Press 'C' for Canadian Dollars.\n");
printf("Press 'E' for Euros.\n");
printf("Press 'K' for Swedish Krona.\n");
printf("Press 'Y' for Japanese Yen.\n");
printf("Press 'P' for British Pounds.\n\n");
printf("Press 'Q' to quit.\n\n");

nation=getchar(); //Retrieves users choice and assigns "nation"
variable

switch (nation) //Selection process to give amount based on user
selection
{
case 'C':
case 'c':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Canadian Dollars.\n\n",
us_dollar, us_dollar * canada_conv);
cont = 0;
break;

case 'E':
case 'e':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Euros.\n", us_dollar, us_dollar
* euro_conv);
cont = 0;
break;

case 'K':
case 'k':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Swedish Krona.\n", us_dollar,
us_dollar * krona_conv);
cont = 0;
break;

case 'Y':
case 'y':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Japanese Yen.\n", us_dollar,
us_dollar * yen_conv);
cont = 0;
break;

case 'P':
case 'p':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f British Pounds.\n", us_dollar,
us_dollar * pound_conv);
cont = 0;
break;

case 'Q':
case 'q':
cont = 1;
printf("Thanks for using the Currency Conversion program.\n\n");
break;

default: //This is the error check. If the enter an incorrect
choice, they get shut down
break;
}

} while (cont!=1);
//Give user time to see results and end program
printf("\n\nPress any key and Enter to exit the program.\n");
scanf("%d");
return 0;
}

Nov 14 '05 #5
Here is your code corredtion it will work fine..... Enjoy :

"Pete Gray" <pe******@ieee.org> wrote in message news:<gxL3d.19922$wV.4542@attbi_s54>...
Hello Ken,

You probably have "leftover characters" in the input buffer following the
call to scanf() - I've seen this before with progs that mix scanf() and
getchar(). Easiest solution, for this program, is not to mix them. Flushing
the buffer would probably work too, but I've not tried it.

Regards,
-Pete.

"Redduck" <ke**********@mail.com> wrote in message
news:ee*************************@posting.google.co m...
Hello everyone. I am frustrated, I have written the simple program
below for a class and I am having problems with the DO-WHILE loop. On
the first run through the loop, everything works well, the menu is
displayed, the input is registered and the loop runs. On the second
(and following) runs the menu is printed twice. I am sure there is
something very basic that I am missing, but I cannot see it. Can
anyone help?

Thanks in advance.

Ken

****Here is the code****

/* currency.c - Version 1.2
This program receives a selection from the
user to determine the type of currency they
would like the exchange rate for. It then returns
the value of the amount of US currency they entered
in the currency type that they selected.*/

#include <stdio.h>

int main()
{
char nation; //Declare variable for the users choice of currencies

float us_dollar;
float canada_conv;
float euro_conv;
float krona_conv;
float yen_conv;
float pound_conv; //Declare variables of Float type

int cont = 0;

canada_conv = 1.2997; //Set exchange rates for all variables
euro_conv = 1.2056;
krona_conv = 7.5625;
yen_conv = 0.009057;
pound_conv = 0.7694;
us_dollar = 1.00; //set initial dollar amount

printf("Currency Conversion\n\n"); //Title of program

do {

cont = 0;
//Prompt user for currency
printf("Which currency would you like to convert?\n\n");
printf("Press 'C' for Canadian Dollars.\n");
printf("Press 'E' for Euros.\n");
printf("Press 'K' for Swedish Krona.\n");
printf("Press 'Y' for Japanese Yen.\n");
printf("Press 'P' for British Pounds.\n\n");
printf("Press 'Q' to quit.\n\n");

nation=getchar(); //Retrieves users choice and assigns "nation"
variable
getchar(); // this is used to take the character when u press the enter.
// other wise it will re take the character agin and
// whicle loop is going to operate two times.... here is the
// main problem
switch (nation) //Selection process to give amount based on user
selection
{
case 'C':
case 'c':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Canadian Dollars.\n\n",
us_dollar, us_dollar * canada_conv);
cont = 0;
break;

case 'E':
case 'e':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Euros.\n", us_dollar, us_dollar
* euro_conv);
cont = 0;
break;

case 'K':
case 'k':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Swedish Krona.\n", us_dollar,
us_dollar * krona_conv);
cont = 0;
break;

case 'Y':
case 'y':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Japanese Yen.\n", us_dollar,
us_dollar * yen_conv);
cont = 0;
break;

case 'P':
case 'p':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f British Pounds.\n", us_dollar,
us_dollar * pound_conv);
cont = 0;
break;

case 'Q':
case 'q':
cont = 1;
printf("Thanks for using the Currency Conversion program.\n\n");
break;

default: //This is the error check. If the enter an incorrect
choice, they get shut down
break;
}

} while (cont!=1);
//Give user time to see results and end program
printf("\n\nPress any key and Enter to exit the program.\n");
scanf("%d");
why u r using scanf("%d");
remove this..... return 0;
}

Nov 14 '05 #6
ranjeet wrote:
use the getch instead


getch isn't part of the standard library.
What you do in the privacy of your own home,
is your own business, but no getch here.

--
pete
Nov 14 '05 #7
ra***********@gmail.com (ranjeet) wrote:

[ Learn to snip. Do not use cuteisms such as "u" for "you".
Do not top-post. ]
The problem is of the clearence of the buffer:

Now when u enter the choice then after that u have to clear the buffer also.

As u know that *getchar* takes all the input into the buffer and then from
there it takes the value to the allocated mamory.

And the *getch*
There is no getch() in C. There's a getch() in curses, and one in conio;
neither is on-topic here, and in fact IIRC they behave similarly, but
not identically.
So try to use the getch instead of getchar:
Do not do this.
Or use the fflush function:


You can't fflush() an input stream.

All you need to do is filter out the newlines. With the hints of the
other posts in this thread, that shouldn't be hard.

Richard
Nov 14 '05 #8
ranjeet wrote:

The problem is of the clearence of the buffer:

Now when u enter the choice then after that u have to clear the buffer also.


Please do not use silly abbreviations such as 'u' in c.l.c. It is
highly annoying and hard to read. Also do not toppost, your
answer belongs after (or intermixed with) the material to which
you reply, after snipping anything not germane to your answer.

--
"It is not a question of staying the course, but of changing
the course" - John Kerry, 2004-09-20
"Ask any boat owner the eventual result of continuing the
present course indefinitely" - C.B. Falconer, 2004-09-20
Nov 14 '05 #9
ke**********@mail.com (Redduck) wrote in message news:<ee*************************@posting.google.c om>...
Hello everyone. I am frustrated, I have written the simple program
below for a class and I am having problems with the DO-WHILE loop. On
the first run through the loop, everything works well, the menu is
displayed, the input is registered and the loop runs. On the second
(and following) runs the menu is printed twice. I am sure there is
something very basic that I am missing, but I cannot see it. Can
anyone help?

Thanks in advance.

Ken

****Here is the code****

/* currency.c - Version 1.2
This program receives a selection from the
user to determine the type of currency they
would like the exchange rate for. It then returns
the value of the amount of US currency they entered
in the currency type that they selected.*/

#include <stdio.h>

int main()
{
char nation; //Declare variable for the users choice of currencies

float us_dollar;
float canada_conv;
float euro_conv;
float krona_conv;
float yen_conv;
float pound_conv; //Declare variables of Float type

int cont = 0;

canada_conv = 1.2997; //Set exchange rates for all variables
euro_conv = 1.2056;
krona_conv = 7.5625;
yen_conv = 0.009057;
pound_conv = 0.7694;
us_dollar = 1.00; //set initial dollar amount

printf("Currency Conversion\n\n"); //Title of program

do {

cont = 0;

//Prompt user for currency
printf("Which currency would you like to convert?\n\n");
printf("Press 'C' for Canadian Dollars.\n");
printf("Press 'E' for Euros.\n");
printf("Press 'K' for Swedish Krona.\n");
printf("Press 'Y' for Japanese Yen.\n");
printf("Press 'P' for British Pounds.\n\n");
printf("Press 'Q' to quit.\n\n");

nation=getchar(); //Retrieves users choice and assigns "nation"
variable
OVER HERE U JUST ADD ONE MORE STAEMENT getchar();
every thing will work fine.
switch (nation) //Selection process to give amount based on user
selection
{
case 'C':
case 'c':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Canadian Dollars.\n\n",
us_dollar, us_dollar * canada_conv);
cont = 0;
break;

case 'E':
case 'e':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Euros.\n", us_dollar, us_dollar
* euro_conv);
cont = 0;
break;

case 'K':
case 'k':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Swedish Krona.\n", us_dollar,
us_dollar * krona_conv);
cont = 0;
break;

case 'Y':
case 'y':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f Japanese Yen.\n", us_dollar,
us_dollar * yen_conv);
cont = 0;
break;

case 'P':
case 'p':
printf("\nPlease enter the US dollar amount you want to
convert.\n\n");
scanf("%f", &us_dollar); //Gather the dollar amount they wish to
convert
printf("\n$%1.2f US is worth %1.2f British Pounds.\n", us_dollar,
us_dollar * pound_conv);
cont = 0;
break;

case 'Q':
case 'q':
cont = 1;
printf("Thanks for using the Currency Conversion program.\n\n");
break;

default: //This is the error check. If the enter an incorrect
choice, they get shut down
break;
}

} while (cont!=1);
//Give user time to see results and end program
printf("\n\nPress any key and Enter to exit the program.\n");
scanf("%d");
return 0;
}

Nov 14 '05 #10
CBFalconer <cb********@yahoo.com> scribbled the following:
ranjeet wrote:

The problem is of the clearence of the buffer:

Now when u enter the choice then after that u have to clear the buffer also.
Please do not use silly abbreviations such as 'u' in c.l.c. It is
highly annoying and hard to read.


I would have said that but it would have caused yet another flamewar.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"A bee could, in effect, gather its junk. Llamas (no poor quadripeds) tune
and vow excitedly zooming."
- JIPsoft
Nov 14 '05 #11
On 21 Sep 2004 04:12:12 -0700, ra***********@gmail.com (ranjeet)
wrote:
> nation=getchar(); //Retrieves users choice and assigns "nation"
> variable
>

getchar(); // this is used to take the character when u press the enter.
// other wise it will re take the character agin and
// whicle loop is going to operate two times.... here is the
// main problem


And what happens if the user happens to type in multiple characters
before hitting enter?
<<Remove the del for email>>
Nov 14 '05 #12
Barry Schwarz <sc******@deloz.net> wrote in message news:<ci************************@theriver.com>...
On 21 Sep 2004 04:12:12 -0700, ra***********@gmail.com (ranjeet)
wrote:
> nation=getchar(); //Retrieves users choice and assigns "nation"
> variable
> getchar(); // this is used to take the character when u press the enter.
// other wise it will re take the character agin and
// whicle loop is going to operate two times.... here is the
// main problem


And what happens if the user happens to type in multiple characters
before hitting enter?

As each charcter will be replaced with the cuurent chararcter of multilipe
chararcter.
<<Remove the del for email>>

Nov 14 '05 #13
On 29 Sep 2004 22:44:34 -0700, ra***********@gmail.com (ranjeet)
wrote:
Barry Schwarz <sc******@deloz.net> wrote in message news:<ci************************@theriver.com>...
On 21 Sep 2004 04:12:12 -0700, ra***********@gmail.com (ranjeet)
wrote:
>> > nation=getchar(); //Retrieves users choice and assigns "nation"
>> > variable
>> >
> getchar(); // this is used to take the character when u press the enter.
> // other wise it will re take the character agin and
> // whicle loop is going to operate two times.... here is the
> // main problem


And what happens if the user happens to type in multiple characters
before hitting enter?

As each charcter will be replaced with the cuurent chararcter of multilipe
chararcter.


Not until the whole loop iterates again, confusing the user just as it
did the OP.
<<Remove the del for email>>
Nov 14 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2294
by: Aaron Prohaska | last post by:
I have just run into a problem where I have a page that posts back to itself to execute code, except when the page does the post back it somehow executes code that is in our home page for the site....
0
2009
by: Refky Wahib | last post by:
Hi I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million concurrent...
4
2383
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
17
15812
by: Jon Slaughter | last post by:
I'm having a little trouble understanding what the slicing problem is. In B.S.'s C++ PL3rdEd he says "Becayse the Employee copy functions do not know anything about Managers, only the Employee...
18
6136
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
1
1815
by: Refky Wahib | last post by:
Hi Actually I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million...
4
1874
by: Trond Meistad | last post by:
I have a website where I run a simple asp.net web application. On Sunday night, requests to this webapplication started to time out. After much debuggeing with no result, I created a new...
6
3784
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
5
2713
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
6
2327
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
0
7119
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.