Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed My code is not working. Why?

+5 votes
asked May 12, 2021 by 20-CM-043 K kumar (170 points)
closed Sep 20, 2021 by Admin
#include <stdio.h>

int main() {
  float num1;
  double num2;
  int num3;

  printf("Enter a number: ");
  scanf("%f", &num1);
  printf("Enter another number: ");
  scanf("%lf", &num2);
  printf("other one: ");
  scand("%d",  &num3);
  

  printf("num1 = %f\n", num1);
  printf("num2 = %lf", num2);
  printf("\n");
  printf("num3 = %d", num3);

  return 0;
}
closed with the note: answered

12 Answers

0 votes
answered May 15, 2021 by vedanshi (140 points)
you used scand in ur num3 statement its scanf
0 votes
answered May 15, 2021 by Ashritha Reddy (140 points)

In line14 :

 scand("%d",  &num3);

u have given scand instead of scanf

0 votes
answered May 15, 2021 by Burhan Hariyana (170 points)

{
  float num1;
  double num2;
  int num3;

  printf("Enter a number: ");
  scanf("%f", &num1);
  printf("Enter another number: ");
  scanf("%lf", &num2);
  printf("other one: ");
  scanf("%d",  &num3);


  printf("num1 = %f\n", num1);
  printf("num2 = %lf", num2);
  printf("\n");
  printf("num3 = %d", num3);

  return 0;
}

The code works good , only error was that you wrote scand instead of scanf ...

Otherwise it works perfect , Thank you .

0 votes
answered May 27, 2021 by Ramesh Neupane (140 points)

scand("%d",  &num3);

should be

scanf("%d",  &num3);

0 votes
answered Jun 3, 2021 by Bandaru Saikiran (140 points)
place scanf inplace of scand
0 votes
answered Jun 4, 2021 by Ashutosh Kumar Giri (140 points)

replace sacnd into scanf

+1 vote
answered Jun 11, 2021 by 20BQ1A05L5 (160 points)
Replace scand with scanf in line 13
+1 vote
answered Jun 20, 2021 by 19VV1A0428 (680 points)
Replace scand with scanf at 3rd input stage
+1 vote
answered Jun 28, 2021 by Dushyant Singh (160 points)
use cin and cout instead of scanf and printf and calculate seperately

also to use cin and cout add the header file iostream  #include <iostream>

and after  that write:

using namespace std;
+1 vote
answered Jun 29, 2021 by VARSHITH MASHETTY (200 points)
13TH LINE scand to scanf

REMOVE THE EXTRA MARK FROM %f
commented Jun 29, 2021 by Peter Minarik (86,640 points)
"REMOVE THE EXTRA MARK FROM %f"

No.

scanf("%lf") is scanning for long float (64 bit), that is double.
scanf("%f") is scanning for floats (32 bit).

He is right to have lf format specifier for doubles.

Read the documentation https://www.cplusplus.com/reference/cstdio/scanf/
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...