| | |
Conversion to inches
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2008
Posts: 2
Reputation:
Solved Threads: 0
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:
c Syntax (Toggle Plain Text)
#include <stdio.h> #define SIZE 5 double calculateInches1 (double); double calculateInches2 (double); double calculateInches3 (double); double calculateInches4 (double); double calculateInches5 (double); int main(void) { int a[SIZE] = {0,1,2,3,4}; int counter; double inches1, inches2, inches3, inches4, inches5; printf("Please enter value number 1 in inches:"); scanf("%1f",&inches1); printf("Please enter value number 2 in inches:"); scanf("%1f",&inches2); printf("\nPlease enter value number 3 in inches:"); scanf("%1f",&inches3); printf("\nPlease enter value number 4 in inches:"); scanf("%1f",&inches4); printf("\nPlease enter value number 5 in inches:"); scanf("%1f",&inches5); printf("The conversion of value number 1: is %3.2f cm", calculateInches1(inches1)); return 0; } double calculateInches1(double inches1) { return inches1 * 2.54; //printf("The conversion of measure in modifycalculateInches is %3.2f cm", calculateInches(inches)); }
Last edited by Narue; Apr 30th, 2008 at 12:06 pm. Reason: Added code tags
Some snippets
Declare a function
Define a function
C Syntax (Toggle Plain Text)
double myInchesArray[5]; scanf("%lf", &myInchesArray[2] ); // now read about loops
Declare a function
void foo ( double inches[] ); Call a functionfoo ( myInchesArray); Define a function
C Syntax (Toggle Plain Text)
void foo ( double inches[] ) { }
•
•
Join Date: Apr 2008
Posts: 2
Reputation:
Solved Threads: 0
Please, please help me. I made the changes and I'm still having errors:
c Syntax (Toggle Plain Text)
#include <stdio.h> #define SIZE 5 double myInchesArray[5]; void mrinch ( double inches[]); int main(void) { //int a[SIZE] = {0,1,2,3,4}; //int counter; double inches, inches1, inches2, inches3, inches4, inches5; printf("Please enter value number 1 in inches: "); scanf("%lf", &myInchesArray[2] ); printf("\nPlease enter value number 2 in inches: "); scanf("%lf", &myInchesArray[2] ); printf("Please enter value number 3 in inches: "); scanf("%lf", &myInchesArray[2] ); printf("\nPlease enter value number 4 in inches: "); scanf("%lf", &myInchesArray[2] ); printf("\nPlease enter value number 5 in inches:"); scanf("%lf", &myInchesArray[2] ); printf("The conversion of value number 1 is: %3.2f cm", calculateInches(inches)); //printf("The conversion of value number 1 is: %3.2f cm", calculateInches(inches)); return 0; } double calculateInches(double inches) { return inches * 2.54; //printf("The conversion of measure in modifycalculateInches is: %3.2f cm", calculateInches(inches)); }
Last edited by Ancient Dragon; Apr 30th, 2008 at 6:59 pm. Reason: add code tags
•
•
•
•
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.
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.
okay, theres a few things that i can see wrong with your code.
Line 7
your declaring the function "mrinch" ,but the function doesnt exist within your code.
Line 37
your defining the function "calculateInches" but the function hasnt been declared at the top.
maybe your declaration on line 7 should be
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
should be
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.
Line 7
C Syntax (Toggle Plain Text)
void mrinch ( double inches[]);
your declaring the function "mrinch" ,but the function doesnt exist within your code.
Line 37
C Syntax (Toggle Plain Text)
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
C Syntax (Toggle Plain Text)
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
C Syntax (Toggle Plain Text)
printf("Please enter value number 1 in inches: "); scanf("%lf", &myInchesArray[2] );
should be
C Syntax (Toggle Plain Text)
printf("Please enter value number 1 in inches: "); 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.
![]() |
Similar Threads
- Projects for the Beginner (Python)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Conversions (C++)
- Loan Program needs work (C++)
- Green screen!! (Monitors, Displays and Video Cards)
- new to C++ (C++)
- new to C++ redo (C++)
- Very New to Java and need help converting cubic inches to cm (Java)
Other Threads in the C Forum
- Previous Thread: image procesing project
- Next Thread: finding factorial of a number.
| Thread Tools | Search this Thread |
#include * append array arrays asterisks bash binarysearch calculate changingto char character cm copyimagefile creafecopyofanytypeoffileinc createprocess() database dynamic execv feet fgets file floatingpointvalidation fork forloop framework function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide include incrementoperators input intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix meter microsoft mqqueue number oddnumber odf opensource openwebfoundation overwrite owf pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprogramming standard strchr string systemcall testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






