Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
float displayedVal;
float newEntry;
char sym;
displayedVal = 0.0;
printf(" Upisi znak/operator: ");
scanf("%c", &sym);
while (sym != 'Q' && sym != 'q')
{
switch(sym)
{
case 'c':
case 'C':
displayedVal = 0.0;
break;
case '+':
printf(" Upisi broj: ");
scanf("%f", &newEntry);
displayedVal +=newEntry;
break;
case '-':
printf(" Upisi broj: ");
scanf("%f", &newEntry);
displayedVal -= newEntry;
break;
case '*':
printf(" Upisi broj: ");
scanf("%f", &newEntry);
displayedVal *= newEntry;
break;
case '/':
printf(" Upisi broj: ");
scanf("%f", &newEntry);
if (newEntry == 0)
{
printf("\n > Ne mozete dijeliti sa nulom. < ");
newEntry = 1;
}
displayedVal /= newEntry;
break;
default:
printf("\n Upisali ste pogresan znak");
break;
}
printf("\n Rezultat = %f\n", displayedVal);
printf(" Upisi znak/operator: ");
scanf("%c", &sym);
}
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
float displayedVal;
float newEntry;
char sym;
displayedVal = 0.0;
printf(" Upisi znak/operator: ");
scanf("%c", &sym);
while (sym != 'Q' && sym != 'q')
{
switch(sym)
{
case 'c':
case 'C':
displayedVal = 0.0;
break;
case '+':
printf(" Upisi broj: ");
scanf("%f", &newEntry);
displayedVal +=newEntry;
break;
case '-':
printf(" Upisi broj: ");
scanf("%f", &newEntry);
displayedVal -= newEntry;
break;
case '*':
printf(" Upisi broj: ");
scanf("%f", &newEntry);
displayedVal *= newEntry;
break;
case '/':
printf(" Upisi broj: ");
scanf("%f", &newEntry);
if (newEntry == 0)
{
printf("\n > Ne mozete dijeliti sa nulom. < ");
newEntry = 1;
}
displayedVal /= newEntry;
break;
default:
printf("\n Upisali ste pogresan znak");
break;
}
printf("\n Rezultat = %f\n", displayedVal);
printf(" Upisi znak/operator: ");
scanf("%c", &sym);
}
}
program prolazi dva puta kroz petlju i dodeljuje neku nepoznatu vrijednost sto uzrokuje da se ispise poruka "Upisali ste pogresan znak"
ako na kraju stavim jos jednom scanf("%c", &sym); radi normalno. :/
Evo slika kako to izgleda...
http://www.mycity.rs/slika.php?slika=145463_91771718_digitron.JPG]