I'm dealing with an array of pointer structures and I'm very new to pointers. But my issue is specifically with void add(), since that's the only one I've got so far:
#include <iostream>
usingnamespace std;
struct Fraction
{
int num;
int den;
};
void add(Fraction* [], char, int&);
void deleteall (Fraction*, int&);
int main()
{
Fraction* fracptrs[20] = {0};
int size = 0;
char slash = '/';
do{
cout<<"Choose an option: \n"
<<"\t1. Add new fraction\n"
<<"\t2. Edit fraction\n"
<<"\t3. Delete fraction\n"
<<"\t4. Find fraction\n"
<<"\t5. Display all fractions\n"
<<"\t6. Show sum of all fractions\n"
<<"\t7. Delete all fractions\n"
<<"\t8. Quit\n"
<<"Your option is... ";
cin>> choice;
if(choice == 1)
{
add(fracptrs, slash, size);
}
}while(choice != 8);
cout << '\n';
system ("pause");
return 0;
}
void add(Fraction* fracptrs[], char slash, int& size)
{
fracptrs[size] = new Fraction;
cout<<"Enter a fraction: ";
cin>> fracptrs[size] -> num >> slash >> fracptrs[size] -> den;
cout<<"\nYou added the fraction: " << fracptrs[size] << '\n';
size++;
}
I know I haven't written all of the code yet. Anyways, my main issue is the second cout statement in the void add() function. It seems to display what I think is the address of the array. How can I make it so that it displays the actual element??? Perhaps, my whole code is wrong...please shed me some light. Thanks :)