Denniz 103 Posting Pro in Training

Some C compiler will give you a warning when your main function does not return an integer.

In this case, do the following changes to the main function:

int main()
{
......
......
return 0;
}
Denniz 103 Posting Pro in Training

Seeing you have made some efforts in coding it yourself, I will take the trouble to go through your long post.

Here are the problems:

1. Initialize all your marks and counters when you declare them:

double mark=0.;
	double std_aver=0.;
	int total_students_counter=0;
	int section_counter=0;
	double studnt_section_aver=0.;
                double course_aver=0.;
	double master_aver=0.;

Remember, make it a habit to initialize your variables, especially those that you will be using for computation.

2. Reinitialize these two variables in the following locations:

do
{
	double total_marks = 0.;	
	total_students_counter=0;

	do
	{
                     /// blah blah blah rest of codes...

This step will correct your section average computation.

3. Computation for course counter is wrong. Use the following instead:

master_aver = course_aver/section_counter;

Note that I replace the total_students_counter with section_counter, because your "course_aver" variable is actually a total of "section averages".

Denniz 103 Posting Pro in Training

Where did you assign the value for variable num?

Denniz 103 Posting Pro in Training

If there's no further issue, please mark the thread as solved. :)

Denniz 103 Posting Pro in Training

There are some more problems with your codes:

1. You never initialized the variable "removed", yet you used it to keep track of the turns:

removed += turn; //Keep a running total of turns

This will lead to unpredictable behaviour.

2. Why use double for all the variables? Since you are dealing with discrete items like coins, you should use integer instead.

3. You should use while-loop for your validity checks. Using if-statement will only check once.

Denniz 103 Posting Pro in Training

There are a number of ways to get out of the loop. One way is to put the break statement when someone wins the game:

if (left < 1)
{
cout << " Player 1, You have one the game!" << endl; 
break;
}

Else, you can set a flag to true whenever someone wins the game, and then put the check for the flag as one of the condition of the while-loop.

Denniz 103 Posting Pro in Training

Look at your line 60 and line 66. This is not the way you decrement the value.

You should do this:

STAMINA = STAMINA - 2;

or this:

STAMINA -= 2;
Denniz 103 Posting Pro in Training

I know it isn't free, but does Visio suits your purpose? Or even MS Word can be used to draw blocks and arrows, if that is what you want.

Denniz 103 Posting Pro in Training

Alright, I will comment base on your latest codes, cos I don't really have time to go through all the posts. Also, I will skip removeAt() function at this moment and focus on the rest.

1. At the main function, you are still passing uninitialized variables "insertItem" and "index" by values to the functions (line 24 and 25). If you have no use for them, take them out from the parameters. Use local variables instead.

2. Line 140 should be this instead:

cout<<"After inserting the item at position "<<index<<", array

3. At line 144, according to your instruction at line 132, it should be the following instead:

numbers[index] = insertItem;

4. Still, if you perform point 3, you are only OVERWRITING the array item, not inserting it. If you are going to continue using integer array for insertion, there are 2 ways you can do about it:

a) Declare a large array size (say 100) initially, fill the first 12 with your numbers and leave the rest. When doing insertion at say position #2, first use a loop to "push back" all items from position #2 onwards, then write the new value at position #2. Something like this:

for(int i=length; i > index;i--)
{
number[i] = number[i-1];
}
number[index] = insertItem;

You need use the variable length to keep track of the up-to-date length of the array that is filled.

b) The second method would be using dynamic memory allocation for the number …

Denniz 103 Posting Pro in Training

Are you sure your program runs fine? At the first glance, there's so many errors in it:

1. Your main function is passing uninitialized variables' values like index and insertItem into removeAt() and insertAT() functions.

2. Inside insertAt() function, index and insertItem are treated as local variables. That's very bad programming. If you don't intend to pass values, you should simply declare those as local variables instead of parameters.

3. In insertAt() function, the variable item is neither initialized nor assigned any values, yet it is used at the end of the function inside the loop. This leads to some undefined behaviour.

4. You only check once for invalid user input. You should use a loop such that the program will always prompt the user for inputs after each invalid inputs.

5. You use insertItem for the item to be inserted, and index for the position to be inserted. Yet in the below code you never used the variable index! You should used it as the index of the array.

numbers[insertItem-1] = insertItem;    
cout<<numbers[insertItem-1]<<" ";

6. Even if you rectify for point number 5, it still doesn't achieve what you want. It merely overwrite the existing array item with the new item, instead of inserting the item into the position stated. To do what you want, all the subsequent array items must be pushed backwards. If you want to use integer array, then you need to manually "grows" the array to cater for the …

VernonDozier commented: Good points. +8
Denniz 103 Posting Pro in Training

You can also convert the integer into a string, and then retrieve the particular nth placed digit of the string.

Denniz 103 Posting Pro in Training

First parameter is wrong. Use char* instead of char. Are you going to change the value of those variables inside the function? If so, pass pointers or reference, else you can simply pass by values.

Denniz 103 Posting Pro in Training

Also, I've been thinking if i really need to promt the user to input value of x
How can i make the program to get those int values from 1 to 5 and display all of them?

No where in the question says you need to prompt the user. You can simply initialize Count to 1 before the while loop, and increment the value within the loop.

Denniz 103 Posting Pro in Training

What language you use? What's your level of proficiency? And how much time you have?

Denniz 103 Posting Pro in Training

You still don't get it.

It should be:

ticketstotal - moneyprizes - (ticketstotal * percentticket/100.)

Denniz 103 Posting Pro in Training

alright thanks Denniz :D
im almost finished just one problem. when i run it instead of getting 230000.00 i get 234998.00 ? im using float now no more int.

That's because you deducted the wrong thing. Instead of deducting the total admin overhead, you deducted the $2 admin fee!

This question is actually very straightforward, apart from the programming syntax, you should also understand the logic behind all these calculations. Understanding of logic doesn't need programming background.

Denniz 103 Posting Pro in Training

now im having issues on calculating these things
Amount deducted for prize money: $ 15000.00
Balance raised for charitable fund: $ 230000.00

What's the difficulty in calculating these two items? The first one is straight from the value the user entered, the second was just the total revenue deducting the admin fee & prize money.

and idk why but the setprecision is not working on
Revenue generated from ticket sales: $ 250000.00
it works fine for
Amount deducted for administrative overhead: $ 5000.00

?????

That's because you are using integers. Alright, put a decimal point behind the number "5" and magic will appears.

anbuninja commented: thanks for all the help =] +1
Denniz 103 Posting Pro in Training

I believe you need to use recursive functions.

Denniz 103 Posting Pro in Training

When you are using the printf function:

printf("%s", a);

The function is treating variable "a" as a pointer to the beginning of a stream of characters. However, it doesn't have the information about how long the stream of characters is, it has no knowledge that "a" is defined as an array. Thus, the function will simply read from the beginning of the address that "a" points to, byte by byte, until it encounters the null character which indicates the end of a character string.

Integer, float and other types are not used to represent string.

Denniz 103 Posting Pro in Training

okay i got 1. updated but im still lost in question 2. about the percent.

ohhh and i know at the end i havent called out all the variables i know how to do that its just that im soo stuck in the input.

The total admin charges is calculated as follows:

cout << percentticket/100. * ticketstotal << endl;

Remember to put a decimal point behind the 100 so that the resultant value becomes a floating point instead of an integer.

Denniz 103 Posting Pro in Training

what should i change it to??

Switch the position of the two lines stated, as in:

#include <iostream>
#include <cstring>
using namespace std;
#include "SkipCard.h"
Denniz 103 Posting Pro in Training

im using Dev C++.. the code at main file has no problem.. i try without using header file..
The program can work..

So the problem is i dont know how to change it to using header file

Please see my solution above.

Denniz 103 Posting Pro in Training

There's a few problems to your codes.

Basically, to solve your error, you just have to interchange the below two lines:

#include "SkipCard.h"
using namespace std;

However, I believe the below line will give u an error:

if (input=="skip")

You should use the compare method of string instead.

Finally, it is not a good practice to do your function definition in header file. You should do function declaration in header file and put the function definition in source file instead.