You did not finish off the main() function with a }, so you're attempting to define a function within a function, which is not allowed.
You did not finish off the main() function with a }, so you're attempting to define a function within a function, which is not allowed.
apparently there is something wrong with my for loop; it compiles but after it asks for the hours for car 1 it asks for the rest of the cars but just assumes 0 and jumps to the end
any idea why?
Looks like someone skipped hello world lesson.
once again, beginner here just asking for help. im the one who has written this code, its not like i had someone do it for me, so you can either fulfill the purpose of the thread and help or just not reply
No, what you did was bash away at your keyboard for a while without thinking.
Then dumped the whole sorry mess on the board for someone else to fix.
Except simply posting all the fixes won't teach YOU
a) HOW to fix your own problems
b) HOW to avoid making the same mistake again in future.
We are guides to help you on your journey, not pack horses to give your lazy ass a free ride through life.
If you can't deal with this, then just give up trying to be a programmer.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
ha im not trying to be a programmer, its just a class required for my major. As i said earlier my program compiles but it doesnt actually loop through the for loop, it just goes through one time and after trying several times i posted on here that i was having trouble and i just get told that im not trying and you arent just going to do it for me
sorry if im getting agitated, ive been working on this thing for about a week now.
this is my for loop
it compiles, but my loop isnt working right. its asks you for the first input but then it doesnt ask for the next input the following times through the loop. so it just looks like this:Code:#include <stdio.h> #include <math.h> float calculateCharges(float); const int NUMBER_OF_CARS= 8; main() { int cars[NUMBER_OF_CARS]= {1,2,3,4,5,6,7,8}; float charges[NUMBER_OF_CARS]; float hours= 0.0; float totalHours= 0.0; float totalCharges= 0.0; int i; for(i=0; i<NUMBER_OF_CARS; i++){ printf("\nEnter the hours for car %d: ",cars[i]); scanf("%.1f",&hours); }
Enter the hours for car 1: 6
Enter the hours for car 2:
Enter the hours for car 3:
Enter the hours for car 4:
Enter the hours for car 5:
Enter the hours for car 6:
Enter the hours for car 7:
Enter the hours for car 8:
can someone please help me with this
Maybe reading this FAQ entry would help.
maybe im just an idiot but i didnt see how to implement that too my loop
I think you should really start listening to what people here are saying and drop this attitude of "I don't need this, I just want to get this done and over with so I never have to worry about it again". This DOES NOT WORK! You are not writing an essay on the American Civil War here.
So, let me break it to you, unless you understand what you are doing you will not get this done. I promise you.
Now, let's start with the basics again:
1) main() should be
int main(void)
and should
return 0;
At the end of the function.
2) Read the article you have been given from the FAQ AGAIN especially the 5th code snippet discussed there. That's of most interest to you now. Get the user's input correctly and post what you have after making these 2 changes.
Last edited by claudiu; 11-26-2010 at 09:43 AM.
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.
whenever i put the return 0 at the end of my function, it just makes the loop stop after one time through
i am an extreme beginner so i know you probably feel like youre trying to teach a brick wall but i promise i really am trying to do this on my own. its just all another language to me
Of course it's frustrating - but follow the advise you're being given, and give it a good go.
Let me see what's up with your code here...
OK,
1) You DO have to add a closing brace to main()
2) there is no plain main() in C, only int main(void) or int main(argc, *argv[]).
I know you like to discuss these things, but for now, just DO and let's move along here, as only doers can.
3) Add the return 0; as the last line of code in main.
4) Remove the "%.2f" from the scanf("%.2f", for the hours. My compiler won't even stop to scanf() that:
You limit the amount of digits after the decimal point when you print, not when you take in the data. Not necessary, since 2.5 is perfectly fine for an entry, and if it becomes 2.500001 or whatever the nearest float approximation to 2.5 is, then that will be printed out properly with %.2f.Code:scanf("%f", &hours); //what you want
Last edited by Adak; 11-26-2010 at 10:43 AM.
this is what my code is suppose to print out
Enter the hours for car 1:
Enter the hours for car 2:
Enter the hours for car 3:
Enter the hours for car 4:
Enter the hours for car 5:
Enter the hours for car 6:
Enter the hours for car 7:
Enter the hours for car 8:
Cars Hours Charges
1
2
3
4
5
6
7
8
TOTAL
and then based on the inputs they will fill in the empty slots of the table