it is not your loop it is what you're doing with your other code that is faulty. But you're using conio.h, which is DOS. so that behavior you say you're getting .. humm.
Code:
#include <stdio.h>
#include <conio.h>
//here main is not declaried properly
// void is not valid anymore.
void main (void)
{
char moikka;
printf ("Hello! Welcome to the Calculator\n");
printf ("Press x if you want to continue\n\n");
// here you got infinite loop setup already
while(1) {
//here you're telling look for an int
//and using char
scanf("%d", &moikka);
//here you telling to print a int
// and using char
printf("Your letter was: %d", &moikka);
// %d makes no sense at all
// even d == 'x'
// d is not declared.
// you are using the wrong thing
// moikka is what yo uneeded to use as a char across the board. But you're
// using int for numbers, so now you're crossing the board using apples and oranges logic.
if (%d=='x') {
break;
}
getch();
}
printf("\n\nHi");
return;
plus your messages says press X if you want to continue and using x to stop continuing.
take a look at this, I set it up to quit on x because of your break , if you have to put that conio.h back into play then change the getchar() back to getch()
Code:
#include <stdio.h>
//#include <conio.h>
int main (void)
{
char moikka;
printf ("Hello! Welcome to the Calculator\n");
printf ("Press x if you want to quit\n\n");
while(1) {
scanf("%c", &moikka);
printf("Your letter was: %c\n", moikka);
if (moikka == 'x') {
break;
}
getchar();
}
printf("bye\n");
return 0;
}
this one here is something to look at to see how to keep it going until a condition is reached.
Code:
#include <stdio.h>
//#include <conio.h>
int main (void)
{
char moikka;
// you should be using int's for a calculator
//but for the purpose of loops
while( moikka != 'x')
{
printf ("Hello! Welcome to the Calculator\n");
printf ("Press x if you want to quit\n\n"
"Press any other letter to continue\n");
scanf(" %c", &moikka);
printf("Your letter was: %c\n", moikka);
}
printf("bye\n");
return 0;
}