473,508 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

suggest parentheses around assignment used as truth value

1 New Member
the errors come up as suggest parentheses around assignment used as truth value which it says for the lines 7,10,13,16,19 and im just wondering what it is that is wrong with it if anyone could let me know cause im new to this. heres my code:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3.     int main(int argc,char*argv[]){
  4.     int integer;
  5.     printf("please enter an integer \n");
  6.     scanf("%d", &integer);
  7.     if (integer=(1)){
  8.     printf ("you entered: \n one");
  9. }
  10.     if (integer=(2)){;
  11.     printf ("you entered: \n two");
  12. }
  13.     if (integer=(3)){;
  14.     printf ("you entered: \n three");
  15. }
  16.     if (integer=(4)){;
  17.     printf ("you entered: \n four");
  18. }
  19.     if (integer=(5)){;
  20.     printf ("you entered: \n five");
  21. }
  22.     if (integer<1){;
  23.     printf ("you entered a number less then one\n");
  24. }
  25.     if (integer>5){;
  26.     printf ("you entered a number greater than five");
  27. }
  28.     return 0;
  29. }
  30.  
  31.  
the lines 7, 10, 13, 16 19 are the ones with the "integer=number" part
Mar 17 '13 #1
1 4350
weaknessforcats
9,208 Recognized Expert Moderator Expert
This code:
Expand|Select|Wrap|Line Numbers
  1.  if (integer=(1)){
  2. etc...
should be:
Expand|Select|Wrap|Line Numbers
  1.  if (integer == 1){
  2. etc...
The = may mean "equals" in mathematics but in C and C++ it means "assignment". The original code would try to change the integer entered to 1 instead of testng it for 1.

Note that if (integer=(1)) will always be true since 1 is true. That means the code following it can never be reached and that is what the compiler is frowning about.
Mar 17 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1975
by: peter | last post by:
I've got a table which is used for storing votes, each row has a field with a reference to the user who's been voted for and i'd like to simply get the user ref with the most votes,or if tied,...
1
1202
by: antonyliu2002 | last post by:
Suppose that I have the following on my web: Your annual income: o > o < ___________ If the user enters a number in the textbox indicated by the underline, but forget to click either of...
90
3365
by: John Salerno | last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? False print 'hi' hi Thanks.
18
15097
by: lovecreatesbea... | last post by:
Isn't code at line 2 correct? a.c:2: warning: suggest parentheses around && within || int isleap(int year){ if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) /*line 2*/ return 1;...
6
17093
by: natkw1 | last post by:
Hi all, I'm new to C and kind of confused on this. I've had a look around this group for suggestions but still not sure why the warning is occurring. What I've done is this <code snip> void...
3
2542
by: Lyn | last post by:
Can anyone explain this for me? A sub procedure can be called with or without parentheses around the arguments. By personal convention, I normally use parentheses. I am in the middle of a...
6
9091
by: billelev | last post by:
This is probably very easy, but I can't see how you would do this... I have a table that is used as a source table for a report. The table contains percentage values. In the report, I would like...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5631
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.