Join 149,986 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,410 people online right now. Registration is fast and FREE... Join Now!
i am new with arrays, and would appreciate any help with this. I have to compare the numbers in both arrays to see when the numbes in one array exceeds the numbers in the second array. I am first trying to get the array 1 to compare the numbers within itself and print out the highest number. here is my code and the errprs I am getting. thanks in advance for the help
got it...thanks! Here are the changes I have made so far...I'm posting as I go as I might need alittle morehelp later withthis project. I have to put this in a function...gonna see what I can 1st
ok now I have to do the average of the array. I have not done this before and cannot seem to find an example of it in my book or online. If someone could could give me a shove in the right direction I would appreciate it. Here is my code below.
Your line "if (firstavg = avg + CalcAvg1[i]);" doesn't make any sense - why are you using an assignment statement inside an if statement? Did you mean
CODE
if (firstavg == avg + CalcAvg1[i])
This will run the next line
CODE
firstavg = firstavg/CalcAvg1[i];
if it is true.
To be frank, I'm not sure either way how this works...
Here is the way you calculate the average of an array - I would suggest you to paraphrase this example for your work
CODE
float avg = 0; //always make avg at least a float int count = //size of array int sum = 0; //to calculate sum total of array elements; always initialize this to 0
for (int i=0; i<count; i++) { sum = sum + array1[i]; //you could also say sum += array[i]; } // these parentheses are optional since there is only one statement inside the loop, but that's for you to decide depending on your comfort level with the language
avg = sum/count; //calculates the average
return avg;
Let me know if you need any further explanation. Cheers!
ok, I changed my code up again...still not getting the output. I'm getting 0.00...when I manually calculate it I get 36.48. Can you see where I might be going wrong?.... again
If you are going to use floats then in your calculations you also need to use floats. If you use integers to store the float values, you will receive a loss of precision. Basically you will lose anything after the decimal point.
Secondly if you are going to output the average, then output the average not the counter. Unless you have a specific reason for outputting the counter, in which case it should look like this printf("%d", counter4);, you need to use the correct format specifier in order to see the value.
Last but not least you must initialize your counter4 variable, otherwise you are incrementing whatever value was already stored in that memory location.
I have a header file that was supplied to us. i saved it as a .h extension in the folder with the sourcefile. when I try to call it, it says that PrintTitle(); is an undeclaired variable. How do i use it, or did I saveit to the wrng spot. thanks
void PrintTitle () /*Function to display the company title*/ { printf("Bethazor's Stats Lair\n"); printf("---------------------\n"); }
void PrintDate () /*Function to display current date */ { rintf("Date = %s", __DATE__); /*2 underscores precede and follow DATE */ }
void PauseScreen () { printf("Press any key to continue"); getch(); }
and here i am attempting to use it. Please tell me what i am doing wrong. I haved it in the folder that has the source code, not the debug folder or the compiler folder. I also tried using it like this <util.h> and just util.h .