| | |
i need help pleaz >>
![]() |
•
•
Join Date: Oct 2008
Posts: 50
Reputation:
Solved Threads: 0
hello every body
i have a problem with a c program .
the question that ( write a c program that reads a real numbers untill error then calculate the sum and the average of all numbers )
i have solve it with a while looping . and i need it with adiffrent looping .
i have a problem with a c program .
the question that ( write a c program that reads a real numbers untill error then calculate the sum and the average of all numbers )
i have solve it with a while looping . and i need it with adiffrent looping .
C Syntax (Toggle Plain Text)
#include<stdio.h> void main() { float total,average; int s; float a; while((scanf("%f",&a)>0)) { total=total+a; s=s+1; } average =total/s; printf("The sum of numbers are %f and the average is %f",total,average); }
Last edited by bahr_alhalak; Jun 24th, 2009 at 7:02 pm.
•
•
Join Date: Mar 2008
Posts: 1,522
Reputation:
Solved Threads: 127
I don't get it, what's your problem?
Also, don't use void main, replace it with int main.
Also, don't use void main, replace it with int main.
Last edited by William Hemsworth; Jun 24th, 2009 at 7:09 pm.
I need pageviews! most fun profile ever :)
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Oct 2008
Posts: 50
Reputation:
Solved Threads: 0
thaaaaaanx WaltP ;
i am still trying
i am still trying
C Syntax (Toggle Plain Text)
#include<stdio.h> #include<conio.h> int main() { float total,average; int s; float a; clrscr(); do { total=total+a; s=s+1; } while((scanf("%f",&a)>0)); average =total/s; printf("The sum of numbers are %f and the average is %f",total,average); }
Last edited by bahr_alhalak; Jun 25th, 2009 at 4:06 am.
Changing it to a for loop is not that difficult, look up how a for loop works, or take a look at this small example:
And because you're so kind I've also Googled up a tutorial about Control structures (if, while, do-while, for): http://www.cplusplus.com/doc/tutorial/control/
C Syntax (Toggle Plain Text)
int i; // declare this variable before any statement in your code for(i = 0; i < 5; i++) { /* The code in this code block will run five times */ }
Last edited by tux4life; Jun 25th, 2009 at 6:13 am.
"You can't build a reputation on what you are going to do."
•
•
•
•
>for(int i = 0; i < 5; i++)
That code where 'i' is declared with the parenthesis
...
'for' loop initial declaration used outside C99 mode JFYI

C89:
C Syntax (Toggle Plain Text)
int i; // declare this variable before any statement in your code for(i = 0; i < 5; i++) { /* The code in this code block will run five times */ }
C99:
C Syntax (Toggle Plain Text)
for(int i = 0; i < 5; i++) { /* The code in this code block will run five times */ }
Last edited by tux4life; Jun 25th, 2009 at 6:16 am.
"You can't build a reputation on what you are going to do."
![]() |
Similar Threads
- i need help pleaz >> (Java)
- all corner is destroy!pla help (HTML and CSS)
- Problems with MSN Explorer & Live Messenger (Web Browsers)
- VB Report (Visual Basic 4 / 5 / 6)
- Pert/ (C)
- what is classes? (C++)
- Help ME (C++)
Other Threads in the C Forum
- Previous Thread: i need modification for this c programming game .the line should be no more than 120
- Next Thread: display students sorted by id
Views: 821 | Replies: 16
| Thread Tools | Search this Thread |
Tag cloud for C
2darray api array arrays behaviour binary binarysearch c++ char character code coke command conversion convert copyimagefile creafecopyofanytypeoffileinc database decimal directory dude dynamic error exec factorial fgets file fork function functions getlasterror givemetehcodez grade graphics help.forensic homework i/o input insert int integer lazy library line linked linkedlist linux list lists locate logical_drives loop malloc matrix memory motherboard mysql newbie no-effort opensource operator output path pointer pointers printf problem process program programing programming read recursion recursive recv reverse roman scanf scripting sms_speak socketprograming spoonfeeding stdout steganography string strings strtok structures student suggestions syntax system systemcall turbo-c turboc unix user variable windows words






