Conversion to inches

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 2
Reputation: Maabou is an unknown quantity at this point 
Solved Threads: 0
Maabou Maabou is offline Offline
Newbie Poster

Re: Student with a "C" question

 
0
  #1
Apr 30th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Conversion to inches

 
0
  #2
Apr 30th, 2008
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. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 2
Reputation: Maabou is an unknown quantity at this point 
Solved Threads: 0
Maabou Maabou is offline Offline
Newbie Poster

Re: Conversion to inches

 
0
  #3
Apr 30th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Conversion to inches

 
1
  #4
Apr 30th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,039
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Conversion to inches

 
1
  #5
Apr 30th, 2008
Originally Posted by Salem View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: Conversion to inches

 
0
  #6
May 1st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 40
Reputation: midimatt is an unknown quantity at this point 
Solved Threads: 2
midimatt's Avatar
midimatt midimatt is offline Offline
Light Poster

Re: Conversion to inches

 
0
  #7
May 3rd, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC