i read in a file and arrange the file to something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
1
2
3
3
4
5
7
7
8
8
9
9
9
10
10
10
10
what i want is for all the numbers to appear only once. theres no 6 btw.
all i got right now for the code is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
for (int x = 0; x < size; x++)
{
for (int num = 1; num < 11; num++)
{
int count = 0;
if (p[x] == num)
{
count++;
cout << p[x] << endl;
x = x + count;
}
}
}
Now, when you read a number from file, check to see if it is in the array. If it is not, add it to the array. But if it is already in the array, do nothing.
You will be helped to keep the array sorted at all times -- but that is not strictly necessary. You could sort it afterward. Or, assuming your input is always sorted, you can avoid the sorting entirely and just check to see whether the last number is the same as the current number.
if the numbers are strictly in ascending order you could simply just read the first number in a temporary variable then start reading next numbers when you encounter a new number you output the number stored in the temporary variable then you assign the new encountered number to the temporary variable, and repeat those steps
thanks that worked. but uh... idk how to say this lol... theres a second part to this xD. originally i just wanted to make the numbers appear only once before i moved on(there was actually more numbers). but with the code that you gave, it doesnt really work with the second part.
i was supposed to add the amount corresponding to the person. so for person 10, the total amount should be 1130 and the total amount2 should be 468.
sorry for not being specific xP. honestly i thought if i could just find a way to change the output layout, i can squeeze in the code to calculate the total. but i couldnt x( but thanks tho
this is what i had in mind: if i can get the code to print all the person# once, then i can add some code onto that loop to add all the corresponding amounts at the same time.
even though i didnt include this but i already read in from the file in my main code and called a function to arrange them from lowest to highest. now i want to call another function within the first function to add up the amounts corresponding to its person#.
sorry it took a little while to respond. im currently trying your array of totals and still havent gotten any further xd