In this part I need to have a calculation that mutiplies by 2 in order to display the Purchase amount. I know I need to have another array I just don't know where to put it or how to address. I have written a comment of an if else that I thought would work but I am not quite sure.
Code:
#include<iostream>
#include<iomanip>
#include<fstream>
#include <stdlib.h>
using namespace std;
struct info_struct
{
char ID[5];
int number_year;
int number_CD;
};
void Display(info_struct[], int);
void Passing(info_struct[], int);
int main()
{
int total_on_hand = 0;
// int i;
char select;
cout << setprecision(2)
<< setiosflags(ios::fixed)
<< setiosflags(ios::showpoint);
info_struct info[4] =
{{"M123" , 2, 3},
{"M225", 1, 6},
{"M248", 2, 1},
{"M552", 3, 5}};
do
{
cout << "\n";
cout << "Mr. Muzik's Fanatastic Music Club\n";
cout << "==================================\n";
cout << "A - Display Annual Report\n";
cout << "B - Input Information\n";
cout << "Please make a selection: ";
cin >> select;
cin.ignore(80, '\n');
switch(select)
{
case 'A':
case 'a':
Display(info, 4);
break;
case 'B':
case 'b':
Passing(info, 4);
break;
default:
cout << endl << endl
<< "Invalid Property Code! Try again.\n" << endl;
break;
}
}while((select != 'a' || select != 'A') && (select != 'B' || select != 'b'));
return 0;
}
void Display(info_struct NEW[], int size)
{
//int Pur[4];
int i;
int total_on_hand = 0;
cout << endl << endl;
cout << setw(20)<< "ID"
<< setw(20) << "Number of Year"
<< setw(20) << "Number of CD bought"
<< setw(20) << "Purchase\n" << endl;
for (i = 0; i < size; ++i)
{
/*
if(NEW[i].number_year < NEW[i].number_CD)
{
total_on_hand = NEW[i].number_year * 2;
}
else if(NEW[i].number_year > NEW[i].number_CD)
{
total_on_hand = NEW[i].number_CD * 2;
}
*/
cout << endl;
cout << setw(20)<< NEW[i].ID
<< setw(20)<< NEW[i].number_year
<< setw(20)<< NEW[i].number_CD;
}
}
void Passing(info_struct NEW_2[], int size_2)
{
char file_name[81];
int i;
cout << "\nEnter the name of the file you want to write to: ";
cin.getline(file_name, 81);
ofstream out_file(file_name);
if (!out_file)
{
cout << "\nERROR: File could not be opened.";
exit(1);
}
out_file << endl << endl;
out_file << setw(20)<< "ID"
<< setw(20) << "Number of Year"
<< setw(20) << "Number of CD bought" << endl;
for (i = 0; i < size_2; ++i)
{
out_file << endl;
out_file << setw(20)<< NEW_2[i].ID
<< setw(20)<< NEW_2[i].number_year
<< setw(20)<< NEW_2[i].number_CD << endl;
}
}
I posted the whole code so that you can see how it falls into place and the if else is in the Display Funtion