C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 27th, 2005, 11:06 PM
bigdaddy bigdaddy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 4 bigdaddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 52 sec
Reputation Power: 0
Exclamation Urgent Tutorial HELP!!!!

thanx everyone...there are a lot of programming experts down here

Reply With Quote
  #2  
Old September 27th, 2005, 11:16 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
Ok, first off how urgent is this, like is it due tomorrow? Second off let me see if I got this right. You need to read the data from a text file and have the program calculate the test results and display them or do you need to out put a seperate file for the results?

Reply With Quote
  #3  
Old September 28th, 2005, 03:57 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 995 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 13 h 57 m 35 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Something like this?
c Code:
Original - c Code
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define PI 3.14159265
  4.  
  5. int main(void)
  6. {
  7.     FILE *fp;
  8.     int i, j, substances, experiments, inval, outval, maxsub;
  9.     double tempval, sumval, maxval;
  10.    
  11.     fp = fopen("refraction1.txt", "r");
  12.  
  13.     fscanf(fp, "%d\n", &substances);
  14.  
  15.     for(i = 0, maxval = 0.0; i < substances; i++)
  16.     {
  17.         printf("Substance No.%d\n", (i+1));
  18.         fscanf(fp, "%d\n", &experiments);
  19.         for(j = 0, sumval = 0.0; j < experiments; j++, sumval += tempval)
  20.         {
  21.             fscanf(fp, "%d %d\n", &inval, &outval);
  22.             tempval = sin(((double) inval) * PI / 180) / sin(((double) outval) * PI / 180);
  23.             printf("Data No.%d Angles(in:%d, out:%d) Rindex = %.2f\n", (j+1), inval, outval, tempval);
  24.         }
  25.         tempval = (sumval / experiments);
  26.         printf("Average Rindex = %.2f\n\n", tempval);
  27.         if(tempval > maxval)
  28.         {
  29.             maxval = tempval;
  30.             maxsub = i + 1;
  31.         }
  32.     }
  33.     printf("Substance No.%d has the maximum refraction index of %.2f\n", maxsub, maxval);
  34.     fclose(fp);
  35.     return 0;
  36. }
Comments on this post
MichaelSoft agrees: Nice compact solution (where is the comment ;-)) ... {and why can't I give you points for it}
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 275

Last edited by Itsacon : September 28th, 2005 at 04:50 AM. Reason: typo

Reply With Quote
  #4  
Old September 28th, 2005, 04:54 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 995 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 13 h 57 m 35 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Note, if you want the output to a file, and not the screen, either pipe it there, or add an
c Code:
Original - c Code
  1. fo = fopen("ouput.txt", "w");

to the beginning of the main() (next to the fopen for the input file) and replace all occurences of
Code:
printf(
with
Code:
frpintf(fo,

Reply With Quote
  #5  
Old September 28th, 2005, 05:02 AM
MichaelSoft MichaelSoft is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The Netherlands
Posts: 121 MichaelSoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 20 sec
Reputation Power: 4
So now we are making homework for others?
To my opinion one should show some code he has, and must point out where he got stuck. Building a complete solution from scratch will not help him learn anything...

Not that I can help myself sometimes ;-).

Reply With Quote
  #6  
Old September 28th, 2005, 05:26 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 995 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 13 h 57 m 35 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Yeah well, if we don't give him the code, he'll copy it off a classmate :-)
Besides, little parsers like this are so damn easy, I consider it a waste not to write them :-)

As for the points, I believe you can only give a certain amount of points to one user within a certain timespan.
See here

Reply With Quote
  #7  
Old September 28th, 2005, 05:43 AM
bigdaddy bigdaddy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 4 bigdaddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 52 sec
Reputation Power: 0
Thanx Guys, You Saved me.. :)

Quote:
Originally Posted by Geo.Garnett
Ok, first off how urgent is this, like is it due tomorrow? Second off let me see if I got this right. You need to read the data from a text file and have the program calculate the test results and display them or do you need to out put a seperate file for the results?


oh it supposed to be due in about 8hours time from when u last posted... anyway the program that u wrote is perfect...its works...thanx u just saved my ass..hahaha

Reply With Quote
  #8  
Old September 28th, 2005, 06:04 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 995 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 13 h 57 m 35 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Why did you remove your original post?
This way, this thread is of no use to other users anymore.

Reply With Quote
  #9  
Old September 28th, 2005, 07:23 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 995 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2Folding Points: 802356 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 13 h 57 m 35 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Original post.

To all latecomers, bigdaddy had a homework assignment he was too noob to understand, which essentlially was:

How to convert:
Code:
Input
3 // number of substances
5 // number of experiments for first substance
50 50 // in angle and out angle for first experiment
40 41 // etc
30 30
10 9
60 60
2 // number of experiments for second substance
35 26
63 42
3 // etc
20 8
50 18
71 23


To:
Code:
Output
Substance No.1
Data No.1 Angles(in:50, out:50) Rindex = 1.00
Data No.2 Angles(in:40, out:41) Rindex = 0.98
Data No.3 Angles(in:30, out:30) Rindex = 1.00
Data No.4 Angles(in:10, out:9) Rindex = 1.11
Data No.5 Angles(in:60, out:60) Rindex = 1.00
Average Rindex = 1.02

Substance No.2
Data No.1 Angles(in:35, out:26) Rindex = 1.31
Data No.2 Angles(in:63, out:42) Rindex = 1.33
Average Rindex = 1.32

Substance No.3
Data No.1 Angles(in:20, out:8) Rindex = 2.46
Data No.2 Angles(in:50, out:18) Rindex = 2.48
Data No.3 Angles(in:71, out:23) Rindex = 2.42
Average Rindex = 2.45

Substance No.3 has the maximum refraction index of 2.45


Where a Refraction index is calculated as:
Rindex = sin(in) / sin(out) (in & out in degrees)
Comments on this post
Geo.Garnett agrees: LOL Itsacon, "to noob to understand" =)..

Reply With Quote
  #10  
Old September 28th, 2005, 11:30 AM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
Im not fast enough

I started trying to help this guy last night. Planning on helping him, but then I slept in, and ya'll just attacked this question. Most of the time a thread stays up for a couple of days before being answered even if there urgent. =) lol but anyway I probably could have done it as good anyways

Reply With Quote
  #11  
Old September 28th, 2005, 11:47 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Doing someone else's homework goes against my beliefs
Hopefully the answers here should help future students in discovering their own solutions.

Reply With Quote
  #12  
Old September 28th, 2005, 11:59 AM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
YA MadCowDzz

I'm a student, Not in my core classes yet, or my programming classes yet So I like when ppl join only to post one or two homework assignments cause it lets me see the difficulty level that maybe some of my assignments might be like once I get there <