#include <iostream>
#include <stdio.h>
usingnamespace std;
int main()
{
int a, b, c, result1, result2;
printf ("Write a number (a): ");
scanf("%d", &a);
printf("Write another number (b): ");
scanf("%d", &b);
printf("Another one (c): ");
scanf("%d", &c);
result1 = a+b-(c+a+b);
result2 = a+b+c;
cout << "The result is: " ;
cout << result1;
cout << " and: " ;
cout << result2 << endl;
if (result1 = 0);
{
cout << "If the result was 0 then C was 0";
}
return 0;
}
Thanks,
I can't understand what's the connection between parantheses at int main with "if" condition not being checked...
With cout, I tried for example merge the first 2 like this : cout << "The result is": result1 ;
And din't work.
I used printf, scanf and std because i didnt know what to use otherwise... And about the expression resulting in -c well i wasn't paying attention, I just tried something to add "if" and see if i understood how to use it.
Edit: I changed if (result1 = 0); in if ((result1 = 0)); and the warning tip disappeared but still the condition is not getting checked.
= is for assignment, whereas == is for comparison - which is what you want for a condition expression. And remove the semicolon on line 26
The following is probably not the worlds best advice (it has it's limitations), write the if statement like this:
1 2 3
if ( 0 == result1) {
}
That way, if you forget to use == , the compiler will complain. But hopefully having made this mistake, you will now remember to always use == for comparison.
For std::cout :
std::cout << "The result is " << result1 << "\n";
Try to use std::cout and std::cin rather than scanf and printf.