Having trouble getting this to display properly
the user has the option to add up to 10 coins then the option to display the coins
i can get it to work if i know how many coins are input using a for loop but for
some reason this has me stump. Any help will be greatly appreciated
#ifndef COINS_H
#define COINS_H
#include <iostream>
#include <string>
using namespace std;
struct Coins
{
int date;
string type;
string country;
};
#endif
#include "Coins.h"
void getCoins(Coins coins[], int SIZE, int count);
void displayCoins(Coins coins[], int SIZE, int count);
const int SIZE = 10;
int main()
{
Coins coins[SIZE];
char answer;
char displayAnswer;
int count = 0;
cout << "Enter up to 10 coins.\n"
<< "Enter a coin (Y/N) ? ";
cin >> answer;
cout << endl;
system("CLS");
if (toupper(answer) == 'Y')
{
count = 1;
getCoins(coins, SIZE, count);
}
cout << "Display the coin(s) (Y/N) ? ";
cin >> displayAnswer;
if (toupper(answer) == 'Y')
displayCoins(coins, SIZE, count);
return 0;
}
void getCoins(Coins coins[], int SIZE, int count)
{
char again = 'Y';
do {
for (int i = 0; i < 1; i++)
{
cout << "DATE: ";
cin >> coins[i].date;
cin.ignore();
cout << "TYPE: ";
getline(cin, coins[i].type);
cout << "COUNTRY: ";
getline(cin, coins[i].country);
}
cout << "Enter another coin (Y/N) ? ";
cin >> again;
system("CLS");
if (toupper(again) == 'Y')
count++;
} while (toupper(again) != 'N');
}
void displayCoins(Coins coins[], int SIZE, int count)
{
cout << "There are " << count << " coins\n\n";
for (int i = 0; i < count; i++)
{
cout << '#' << i + 1 << ".) \n";
cout << coins[i].date << endl
<< coins[i].type << endl
<< coins[i].country << endl;
}
}
What I have tried:
Having trouble getting this to display properly
the user has the option to add up to 10 coins then the option to display the coins
i can get it to work if i know how many coins are input using a for loop but for
some reason this has me stump. Any help will be greatly appreciated