C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 21st, 2012, 07:16 AM
Giorgos Giorgos is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 24 Giorgos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 27 m 36 sec
Reputation Power: 0
What is wrong;

hi to all,
can someone help me
to find out what is wrong into this code and i cannot print the x;

Code:
# include <stdio.h> # include <stdlib.h> # include <iostream> # include<conio.h>   main() {     int p[6];       int i,c;       int x;        printf("Give me 6 number\n");       for(i=0;i<6;i++);       scanf("%d",&p[i]);       printf("%d\n",p[i]);       x=p[1]+p[2];       printf("%d\n ",x);       system("pause");       }
Comments on this post
salem disagrees: Pay attention to formatting before you press 'submit'. No one cares to look at code all on one line

Reply With Quote
  #2  
Old October 21st, 2012, 07:31 AM
G4143 G4143 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 71 G4143 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 39 m 39 sec
Reputation Power: 1
Take a close look at this line

Code:
for(i=0;i<6;i++);


Please note the semi-colon.

Also a note on proper syntax. The main function returns an integer.

Code:
int main()
{
/*C++ implies return 0 while C requires a return 0*/
}

Reply With Quote
  #3  
Old October 21st, 2012, 07:35 AM
Giorgos Giorgos is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 24 Giorgos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 27 m 36 sec
Reputation Power: 0
Quote:
Originally Posted by G4143
Take a close look at this line

Code:
for(i=0;i<6;i++);


Please note the semi-colon.


it must be i<5 right ? but the problem is the x.

Reply With Quote
  #4  
Old October 21st, 2012, 07:36 AM
G4143 G4143 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 71 G4143 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 39 m 39 sec
Reputation Power: 1
No. The problem is the semi-colon at the end of the for statement which creates an empty block. Here what your for statement equals...

Code:
for(i=0;i<6;i++);


Which is the same as

Code:
for(i=0;i<6;i++){}/*Note the empty block*/

Reply With Quote
  #5  
Old October 21st, 2012, 07:38 AM
Giorgos Giorgos is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 24 Giorgos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 27 m 36 sec
Reputation Power: 0
Quote:
Originally Posted by G4143
No. The problem is the semi-colon at the end of the for statement which creates an empty block.


thank you very much!!!!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > What is wrong;

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap