| | |
Please Help me with Arrays
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
I am new to c programming. I am trying to write a parking garage program that uses arrays to find the charge for each car and the total charge. Here is what I have so far. Please help me in any way that you can.
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <math.h> float calculateCharges(float); int NUMBER_OF_CARS = 3; main() { int x = 1; float fHours[NUMBER_OF_CARS]; float fCharge[NUMBER_OF_CARS]; for(x=1; x<=NUMBER_OF_CARS; x++) { printf("Enter number of hours for car %d: ", x); scanf("%f", &fHours[x]); } printf("\n\n"); printf("Car\t\tHours\t\tCharge\n"); for(x=1;x<4;x++) { printf("%d\t\t%.1f\t\t%.2f\n", x, fHours, fCharge); } } float calculateCharges(float fHours) { float fCharge = 0.0; if(fHours < 3) { fCharge = 2.00; return fCharge; } else { fHours = fHours-3; fCharge = ceil(fHours) * 0.5; fCharge = 2.00 + fCharge; if(fCharge > 10) { fCharge = 10; return fCharge; } else return fCharge; } }
Last edited by peter_budo; Nov 8th, 2009 at 7:36 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
![]() |
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Arrays (C++)
- How to Return Multidimensional Arrays (C++)
- C file input/output 2D arrays. (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C Forum
- Previous Thread: About Outp function in conio.h for c or c++?
- Next Thread: gcc warning with -Wwrite-strings flag
Views: 253 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyimagefile copypdffile cprogramme createcopyoffile csyntax directory drawing dynamic executable fflush file fork frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling scripting segmentationfault send shape socketprograming spoonfeeding stack standard string strings structures student systemcall test testautomation unix user variable visualstudio voidmain() wab win32 win32api windows.h





