-1
please enter num1 , op , num2
2e2+6
result= 206.000000

Process returned 0 (0x0)   execution time : 8.657 s
Press any key to continue.

(How to use) ... any way to turn off this !

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
A2Z
  • 13
  • 1
  • 2
    It is not clear what you are asking. Please [edit] your question to show your code (copy & paste as text), the input, the actual output and the expected output. – Bodo Jul 24 '19 at 11:42
  • 1
    Please show your code. What are you talking about? `scanf`? Please read this: [ask] and this: [mcve] – Jabberwocky Jul 24 '19 at 11:47
  • 1
    Please don't answer in a comment. Re-read my first comment and [edit] your question as requested. – Bodo Jul 24 '19 at 11:47
  • Probably you are using `float` or `double` values. You might want to use `int` or similar. – Bodo Jul 24 '19 at 11:49
  • Yes i am using float is that any way to turn off this ! – A2Z Jul 24 '19 at 11:52
  • 1
    Do you need to use floating point numbers? (e.g. `2.5+6`) Please [edit] your question to add all this information. **Don't answer in comments.** All relevant information must be in the question. – Bodo Jul 24 '19 at 13:03

1 Answers1

0

You cannot do this directly, there is no standard format specifier for the scanf function family that rejects scientific notation (such as 1e3) for floator double and there is no directy way to "turn off" the scanfs accepting of numbers in scientific notation.

What you can do is read the input as string. Then you check if the string contains 'E' or 'e' and reject if that's the case.

This naive approach should give you an idea what you could do:

#include <stdio.h>
#include <string.h>

int main()
{
  float x = 0;

  do
  {
    char buffer[100];
    scanf("%s", buffer);

    if (strchr(buffer, 'E') != NULL || strchr(buffer, 'e') != NULL)
    {
      printf("Rejected\n");
    }
    else
    {
      sscanf(buffer, "%f", &x);
      break;
    }
  } while (1);
  //...
}

Instead of checking explicitely for the presence of E and e, you could also check for the presence of any non digit and non decimal point character, IOW reject if the buffer contains any of characters not included in [0123456789.]

Of course you should eventually put this functionality into a function.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115