user2006562
user2006562

Reputation: 75

Write a program that prints sum, product and quotient of two input integers in C

I'm new to the language and all this overflow problems and integer types are getting on my nerves. here is what I have but when I run it I get,

-bash: syntax error near unexpected token `newline'

The code:

#include <stdio.h>
int main(void)
{
   int one, two, s, q, m;
   s = one+two
   q = one/two
   m = one*two
   printf("Enter first positive integer: ");
   scanf("%d", &one);
   printf("Enter second positive integer: ");
   scanf("%d", &two);
   printf("The addition of %d and %d is %d", one, two, s);
   printf("The integer division of %d divided by %d is %d", one, two, q);
   printf("the multiplication of %d and %d is %d", &one, &two, m);
   return 0;
}

Thank you

Upvotes: 0

Views: 19842

Answers (4)

Midhun MP
Midhun MP

Reputation: 107211

These lines makes the problem:

s = one+two
q = one/two
m = one*two

You missed the ; (semicolon)

Change it like:

s = one+two;
q = one/two;
m = one*two;

Also read the input from user first before doing the operations.

Upvotes: 0

ChrisWue
ChrisWue

Reputation: 19040

You are missing the semicolons after

   s = one+two
   q = one/two
   m = one*two

Plus you should perform the calculations after you read the input but that's a different problem.

Upvotes: 0

Alexander
Alexander

Reputation: 8147

You should perform the calculations after you've got the input.

printf("Enter first positive integer: ");
scanf("%d", &one);
printf("Enter second positive integer: ");
scanf("%d", &two);

s = one+two;
q = one/two;
m = one*two;

Upvotes: 1

Mark
Mark

Reputation: 8441

try this:

#include <stdio.h>
int main(void)
{
int one, two;
printf("Enter first positive integer: ");
scanf("%d", &one);
printf("Enter second positive integer: ");
scanf("%d", &two);
printf("The addition of %d and %d is %d", one, two, (one+two));
printf("The integer division of %d divided by %d is %d", one, two, (one/two));
printf("the multiplication of %d and %d is %d", &one, &two, (one*two));
return 0;
}

Upvotes: 0

Related Questions