PrintF and Scanf result is zero [closed]
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
-6
down vote
favorite
I am a beginner working on a code project. I'm simply trying to make my program multiply a user's input by a constant, however when I run the program I only get 0 as a result.
sorry this is a basic question, I just can't find a solution anywhere else.
int main()
double quanity, result;
const double USD = 0.81;
result = USD * quanity;
printf("Please input a number.n");
scanf("%f", &quanity);
printf("%fn", result);
return 0;
beginner c
closed as off-topic by ÃÂìýÃÂñ á¿¥Ã栨Â, Dannnno, Stephen Rauch, ÃÂïÃÂ
ú, 200_success Feb 25 at 22:11
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â ÃÂìýÃÂñ á¿¥Ã栨Â, Dannnno, Stephen Rauch, ÃÂïàú, 200_success
add a comment |Â
up vote
-6
down vote
favorite
I am a beginner working on a code project. I'm simply trying to make my program multiply a user's input by a constant, however when I run the program I only get 0 as a result.
sorry this is a basic question, I just can't find a solution anywhere else.
int main()
double quanity, result;
const double USD = 0.81;
result = USD * quanity;
printf("Please input a number.n");
scanf("%f", &quanity);
printf("%fn", result);
return 0;
beginner c
closed as off-topic by ÃÂìýÃÂñ á¿¥Ã栨Â, Dannnno, Stephen Rauch, ÃÂïÃÂ
ú, 200_success Feb 25 at 22:11
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â ÃÂìýÃÂñ á¿¥Ã栨Â, Dannnno, Stephen Rauch, ÃÂïàú, 200_success
1
This is off topic for code review - code review is for asking for feedback on already-working code. (The problem here is your order, you assign result before you ask for input on quantity, try moving that line below the scanf)
â Gerrit0
Feb 25 at 22:07
add a comment |Â
up vote
-6
down vote
favorite
up vote
-6
down vote
favorite
I am a beginner working on a code project. I'm simply trying to make my program multiply a user's input by a constant, however when I run the program I only get 0 as a result.
sorry this is a basic question, I just can't find a solution anywhere else.
int main()
double quanity, result;
const double USD = 0.81;
result = USD * quanity;
printf("Please input a number.n");
scanf("%f", &quanity);
printf("%fn", result);
return 0;
beginner c
I am a beginner working on a code project. I'm simply trying to make my program multiply a user's input by a constant, however when I run the program I only get 0 as a result.
sorry this is a basic question, I just can't find a solution anywhere else.
int main()
double quanity, result;
const double USD = 0.81;
result = USD * quanity;
printf("Please input a number.n");
scanf("%f", &quanity);
printf("%fn", result);
return 0;
beginner c
edited Feb 25 at 21:51
asked Feb 25 at 21:21
Chase Rang
12
12
closed as off-topic by ÃÂìýÃÂñ á¿¥Ã栨Â, Dannnno, Stephen Rauch, ÃÂïÃÂ
ú, 200_success Feb 25 at 22:11
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â ÃÂìýÃÂñ á¿¥Ã栨Â, Dannnno, Stephen Rauch, ÃÂïàú, 200_success
closed as off-topic by ÃÂìýÃÂñ á¿¥Ã栨Â, Dannnno, Stephen Rauch, ÃÂïÃÂ
ú, 200_success Feb 25 at 22:11
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â ÃÂìýÃÂñ á¿¥Ã栨Â, Dannnno, Stephen Rauch, ÃÂïàú, 200_success
1
This is off topic for code review - code review is for asking for feedback on already-working code. (The problem here is your order, you assign result before you ask for input on quantity, try moving that line below the scanf)
â Gerrit0
Feb 25 at 22:07
add a comment |Â
1
This is off topic for code review - code review is for asking for feedback on already-working code. (The problem here is your order, you assign result before you ask for input on quantity, try moving that line below the scanf)
â Gerrit0
Feb 25 at 22:07
1
1
This is off topic for code review - code review is for asking for feedback on already-working code. (The problem here is your order, you assign result before you ask for input on quantity, try moving that line below the scanf)
â Gerrit0
Feb 25 at 22:07
This is off topic for code review - code review is for asking for feedback on already-working code. (The problem here is your order, you assign result before you ask for input on quantity, try moving that line below the scanf)
â Gerrit0
Feb 25 at 22:07
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
-4
down vote
accepted
You are trying to multiply USD Variable with undefined variable "quanity",
you should make the assignment operation after you get the "quanity" from user.
#include <stdio.h>
void main()
double quanity, result;
const double USD = 0.81;
//Scan the number first
printf("Please input a number.n");
scanf("%f", &quanity);
//then make the assignment operation
result = USD * quanity;
printf("%fn", result);
6
Welcome to Code Review! Please, don't answer questions that are off-topic here.
â Daniel
Feb 25 at 21:56
2
(Most of the code you present needs more indentation, by the way.)
â greybeard
Feb 25 at 23:57
printf("%fn", result);
prints with a default 6 digits after the.'
. Rarely is this wanted with money.
â chux
Feb 26 at 1:33
Usingargv[1]
without first validatingargc >= 2
is not defensive coding.
â chux
Feb 26 at 1:33
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
-4
down vote
accepted
You are trying to multiply USD Variable with undefined variable "quanity",
you should make the assignment operation after you get the "quanity" from user.
#include <stdio.h>
void main()
double quanity, result;
const double USD = 0.81;
//Scan the number first
printf("Please input a number.n");
scanf("%f", &quanity);
//then make the assignment operation
result = USD * quanity;
printf("%fn", result);
6
Welcome to Code Review! Please, don't answer questions that are off-topic here.
â Daniel
Feb 25 at 21:56
2
(Most of the code you present needs more indentation, by the way.)
â greybeard
Feb 25 at 23:57
printf("%fn", result);
prints with a default 6 digits after the.'
. Rarely is this wanted with money.
â chux
Feb 26 at 1:33
Usingargv[1]
without first validatingargc >= 2
is not defensive coding.
â chux
Feb 26 at 1:33
add a comment |Â
up vote
-4
down vote
accepted
You are trying to multiply USD Variable with undefined variable "quanity",
you should make the assignment operation after you get the "quanity" from user.
#include <stdio.h>
void main()
double quanity, result;
const double USD = 0.81;
//Scan the number first
printf("Please input a number.n");
scanf("%f", &quanity);
//then make the assignment operation
result = USD * quanity;
printf("%fn", result);
6
Welcome to Code Review! Please, don't answer questions that are off-topic here.
â Daniel
Feb 25 at 21:56
2
(Most of the code you present needs more indentation, by the way.)
â greybeard
Feb 25 at 23:57
printf("%fn", result);
prints with a default 6 digits after the.'
. Rarely is this wanted with money.
â chux
Feb 26 at 1:33
Usingargv[1]
without first validatingargc >= 2
is not defensive coding.
â chux
Feb 26 at 1:33
add a comment |Â
up vote
-4
down vote
accepted
up vote
-4
down vote
accepted
You are trying to multiply USD Variable with undefined variable "quanity",
you should make the assignment operation after you get the "quanity" from user.
#include <stdio.h>
void main()
double quanity, result;
const double USD = 0.81;
//Scan the number first
printf("Please input a number.n");
scanf("%f", &quanity);
//then make the assignment operation
result = USD * quanity;
printf("%fn", result);
You are trying to multiply USD Variable with undefined variable "quanity",
you should make the assignment operation after you get the "quanity" from user.
#include <stdio.h>
void main()
double quanity, result;
const double USD = 0.81;
//Scan the number first
printf("Please input a number.n");
scanf("%f", &quanity);
//then make the assignment operation
result = USD * quanity;
printf("%fn", result);
edited Mar 4 at 16:25
Chase Rang
12
12
answered Feb 25 at 21:54
Mustafa KatipoÃÂlu
122
122
6
Welcome to Code Review! Please, don't answer questions that are off-topic here.
â Daniel
Feb 25 at 21:56
2
(Most of the code you present needs more indentation, by the way.)
â greybeard
Feb 25 at 23:57
printf("%fn", result);
prints with a default 6 digits after the.'
. Rarely is this wanted with money.
â chux
Feb 26 at 1:33
Usingargv[1]
without first validatingargc >= 2
is not defensive coding.
â chux
Feb 26 at 1:33
add a comment |Â
6
Welcome to Code Review! Please, don't answer questions that are off-topic here.
â Daniel
Feb 25 at 21:56
2
(Most of the code you present needs more indentation, by the way.)
â greybeard
Feb 25 at 23:57
printf("%fn", result);
prints with a default 6 digits after the.'
. Rarely is this wanted with money.
â chux
Feb 26 at 1:33
Usingargv[1]
without first validatingargc >= 2
is not defensive coding.
â chux
Feb 26 at 1:33
6
6
Welcome to Code Review! Please, don't answer questions that are off-topic here.
â Daniel
Feb 25 at 21:56
Welcome to Code Review! Please, don't answer questions that are off-topic here.
â Daniel
Feb 25 at 21:56
2
2
(Most of the code you present needs more indentation, by the way.)
â greybeard
Feb 25 at 23:57
(Most of the code you present needs more indentation, by the way.)
â greybeard
Feb 25 at 23:57
printf("%fn", result);
prints with a default 6 digits after the .'
. Rarely is this wanted with money.â chux
Feb 26 at 1:33
printf("%fn", result);
prints with a default 6 digits after the .'
. Rarely is this wanted with money.â chux
Feb 26 at 1:33
Using
argv[1]
without first validating argc >= 2
is not defensive coding.â chux
Feb 26 at 1:33
Using
argv[1]
without first validating argc >= 2
is not defensive coding.â chux
Feb 26 at 1:33
add a comment |Â
1
This is off topic for code review - code review is for asking for feedback on already-working code. (The problem here is your order, you assign result before you ask for input on quantity, try moving that line below the scanf)
â Gerrit0
Feb 25 at 22:07