PrintF and Scanf result is zero [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash 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;








share|improve this question













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
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 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
















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;








share|improve this question













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
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 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












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;








share|improve this question













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;










share|improve this question












share|improve this question




share|improve this question








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
If this question can be reworded to fit the rules in the help center, please edit the question.




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
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 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




    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










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);







share|improve this answer



















  • 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










  • Using argv[1] without first validating argc >= 2 is not defensive coding.
    – chux
    Feb 26 at 1:33

















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);







share|improve this answer



















  • 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










  • Using argv[1] without first validating argc >= 2 is not defensive coding.
    – chux
    Feb 26 at 1:33














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);







share|improve this answer



















  • 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










  • Using argv[1] without first validating argc >= 2 is not defensive coding.
    – chux
    Feb 26 at 1:33












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);







share|improve this answer















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);








share|improve this answer















share|improve this answer



share|improve this answer








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










  • Using argv[1] without first validating argc >= 2 is not defensive coding.
    – chux
    Feb 26 at 1:33












  • 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










  • Using argv[1] without first validating argc >= 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


Popular posts from this blog

Greedy Best First Search implementation in Rust

Function to Return a JSON Like Objects Using VBA Collections and Arrays

C++11 CLH Lock Implementation