Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include <stdio.h>

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

scanf("%d", num1);
scanf("%d", num2);

num3 = num1 + num2;

printf("The number added is: %d", num3);
}

What is wrong with this. I'm trying to take 2 numbers and adding them and printing out the addition of them

What I have tried:

I looked up what %d meant but I couldn't find the issue. Maybe the number inputed is a string? But I did use %d.

i declared all three variables as an a number (integer).
Posted
Updated 15-Dec-17 8:02am
Comments
jeron1 15-Dec-17 14:03pm    
Try adding an ampersand to the scanfs like,
scanf("%d", &num1);

1 solution

scanf requires the address of a variable to store its values, so your code should be:
C++
scanf("%d", &num1);  // use the addressof operator
scanf("%d", &num2);

See scanf, _scanf_l, wscanf, _wscanf_l[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900