943,708 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1220
  • C RSS
Apr 30th, 2008
0

Re: Student with a "C" question

Expand Post »
I need help desperately. To declare an array to hold 5 fives and pass the entire array to it and convert all the measurements in centimeters. The following is what I came up with:
  1. #include <stdio.h>
  2.  
  3. #define SIZE 5
  4.  
  5. double calculateInches1 (double);
  6. double calculateInches2 (double);
  7. double calculateInches3 (double);
  8. double calculateInches4 (double);
  9. double calculateInches5 (double);
  10.  
  11. int main(void)
  12. {
  13. int a[SIZE] = {0,1,2,3,4};
  14. int counter;
  15. double inches1, inches2, inches3, inches4, inches5;
  16.  
  17. printf("Please enter value number 1 in inches:");
  18. scanf("%1f",&inches1);
  19.  
  20. printf("Please enter value number 2 in inches:");
  21. scanf("%1f",&inches2);
  22.  
  23. printf("\nPlease enter value number 3 in inches:");
  24. scanf("%1f",&inches3);
  25.  
  26. printf("\nPlease enter value number 4 in inches:");
  27. scanf("%1f",&inches4);
  28.  
  29. printf("\nPlease enter value number 5 in inches:");
  30. scanf("%1f",&inches5);
  31.  
  32. printf("The conversion of value number 1: is %3.2f cm", calculateInches1(inches1));
  33.  
  34. return 0;
  35. }
  36.  
  37. double calculateInches1(double inches1)
  38.  
  39. {
  40. return inches1 * 2.54;
  41.  
  42. //printf("The conversion of measure in modifycalculateInches is %3.2f cm", calculateInches(inches));
  43. }
Last edited by Narue; Apr 30th, 2008 at 12:06 pm. Reason: Added code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Maabou is offline Offline
2 posts
since Apr 2008
Apr 30th, 2008
0

Re: Conversion to inches

Some snippets
  1. double myInchesArray[5];
  2. scanf("%lf", &myInchesArray[2] ); // now read about loops

Declare a function
void foo ( double inches[] ); Call a function
foo ( myInchesArray);
Define a function
  1. void foo ( double inches[] ) {
  2. }
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Apr 30th, 2008
0

Re: Conversion to inches

Please, please help me. I made the changes and I'm still having errors:
  1. #include <stdio.h>
  2.  
  3. #define SIZE 5
  4.  
  5. double myInchesArray[5];
  6.  
  7. void mrinch ( double inches[]);
  8.  
  9. int main(void)
  10.  
  11. {
  12. //int a[SIZE] = {0,1,2,3,4};
  13. //int counter;
  14. double inches, inches1, inches2, inches3, inches4, inches5;
  15.  
  16. printf("Please enter value number 1 in inches: ");
  17. scanf("%lf", &myInchesArray[2] );
  18.  
  19. printf("\nPlease enter value number 2 in inches: ");
  20. scanf("%lf", &myInchesArray[2] );
  21.  
  22. printf("Please enter value number 3 in inches: ");
  23. scanf("%lf", &myInchesArray[2] );
  24.  
  25. printf("\nPlease enter value number 4 in inches: ");
  26. scanf("%lf", &myInchesArray[2] );
  27.  
  28. printf("\nPlease enter value number 5 in inches:");
  29. scanf("%lf", &myInchesArray[2] );
  30.  
  31. printf("The conversion of value number 1 is: %3.2f cm", calculateInches(inches));
  32. //printf("The conversion of value number 1 is: %3.2f cm", calculateInches(inches));
  33.  
  34. return 0;
  35. }
  36.  
  37. double calculateInches(double inches)
  38.  
  39. {
  40. return inches * 2.54;
  41.  
  42. //printf("The conversion of measure in modifycalculateInches is: %3.2f cm", calculateInches(inches));
  43. }
Last edited by Ancient Dragon; Apr 30th, 2008 at 6:59 pm. Reason: add code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Maabou is offline Offline
2 posts
since Apr 2008
Apr 30th, 2008
1

Re: Conversion to inches

That's because what I posted were NOT CHANGES, they were hints.

As in, you read them and then think about what they're saying, then apply that fresh insight to your specific problem.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Apr 30th, 2008
1

Re: Conversion to inches

Click to Expand / Collapse  Quote originally posted by Salem ...
That's because what I posted were NOT CHANGES, they were hints.

As in, you read them and then think about what they're saying, then apply that fresh insight to your specific problem.
An implementation of:
Give a man a fish and he will eat for a day. Teach a man to fish and he will eat for the rest of his life.
- Chinese Proverb

Another more popular implementation :
Give a man a fish and he will eat for a day. Teach him how to fish and he will sit in a boat and drink beer all day.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
May 1st, 2008
0

Re: Conversion to inches

Another one: Give man a fish he will keep it for next day. Teach a man how to fish he will keep that fish for another next day.
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006
May 3rd, 2008
0

Re: Conversion to inches

okay, theres a few things that i can see wrong with your code.

Line 7

  1. void mrinch ( double inches[]);

your declaring the function "mrinch" ,but the function doesnt exist within your code.

Line 37

  1. double calculateInches(double inches)

your defining the function "calculateInches" but the function hasnt been declared at the top.

maybe your declaration on line 7 should be
  1. double calculateInches(double inches);


in your scanf calls your always reading the data into the same place so it will overwrite the data each time. the number in the square brackets is the position in the array so in your case between 0(first number) - 4(last number)

your code
  1. printf("Please enter value number 1 in inches: ");
  2. scanf("%lf", &myInchesArray[2] );

should be
  1. printf("Please enter value number 1 in inches: ");
  2. scanf("%lf", &myInchesArray[0] );


and another possible implementation:

Give a man a fish and he will eat for a day, teach a man to fish and he will get tired of eating fish.
Last edited by midimatt; May 3rd, 2008 at 11:58 pm.
Reputation Points: 34
Solved Threads: 4
Light Poster
midimatt is offline Offline
49 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: image procesing project
Next Thread in C Forum Timeline: Help reading a text file of any size





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC