TinhornAdeniyi 0 Light Poster

ok this code has a few quirks that is annoying me
the only part that does not straight up work is the Add a show
i have a problem in increasing the size of the array.

there is also the issue of couting two zeros for the minutes of the time slot

this is my infile
4512 Supernatural Friday 10 00
2373 TDI Monday 8 00
5368 AOTS Monday 7 00
2553 xplay Tuesday 6 30

and the code....

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;
   
       struct Schedule //declaration of struct
    {
           int Show_ID;
           string Title;
           string Day;
           int Hour;
           double Min;
           
           };
      
    void initSchedule(Schedule tvShow[], int& maxshows);// read the file
    void menu(Schedule tvShow[], int maxshows);// User menu
    void addShow (Schedule tvShow[], int& maxshows);// 'A' from menu
    void DisplayShow (Schedule tvShow[], int maxshows);// 'D' from menu
    void ModifyShow (Schedule tvShow[], int maxshows); // 'M' from menu
     
int main()
{
    int maxshows;
    cout<<"Please enter the maximum amount of shows"<<endl;
    cin>>maxshows;
    Schedule tvShow[maxshows];
    initSchedule(tvShow,maxshows);
    menu(tvShow,maxshows);
    
    system("pause");
    return 0;
}

void initSchedule(Schedule tvShow[], int& maxshows)
{
ifstream inFile;
inFile.open("Shows.txt");
int i;
for (i=0;i<maxshows;i++)
{
inFile>>tvShow[i].Show_ID>>tvShow[i].Title>>tvShow[i].Day>>tvShow[i].Hour>>tvShow[i].Min;
}
}


void addShow (Schedule tvShow[], int& maxshows)
{
int old, amount, i=0;
cout<<"How many shows would you like to add"<<endl;
cin>>amount;
old=maxshows;
maxshows=maxshows+amount;
do
{
                         i++;
cout<<"Please enter the Show ID"<<endl;
cin>>tvShow[old+i].Show_ID;
cout<<"Please enter the title of the show"<<endl;
cin>>tvShow[old+i].Title;
cout<<"Please enter the Day the show airs"<<endl;
cin>>tvShow[old+i].Day;
cout<<"Please enter the Hour the show airs"<<endl;
cin>>tvShow[old+i].Hour;
cout<<"Please enter the Minute the show airs"<<endl;
cin>>tvShow[old+i].Min;

}
while(i<amount);
}

void DisplayShow (Schedule tvShow[], int maxshows)
{

     int i;
for (i=0;i<maxshows;i++)
{
cout<<tvShow[i].Show_ID<<" "<<tvShow[i].Title<<" "<<tvShow[i].Day<<" "<<tvShow[i].Hour<<":"<<setprecision(2)<<tvShow[i].Min<<" p.m"<<endl;
}
cout<<endl;
}
void ModifyShow (Schedule tvShow[], int maxshows)
{
     int comp;
cout<<"Please enter the Show ID of the show you are modifying"<<endl;
cin>>comp;
for(int i=0;i<maxshows;i++)
{
if(comp==tvShow[i].Show_ID)
{
cout<<tvShow[i].Show_ID<<" "<<tvShow[i].Title<<" "<<tvShow[i].Day<<" "<<tvShow[i].Hour<<":"<<setprecision(2)<<tvShow[i].Min<<" p.m"<<endl;
cout<<"Please enter the new Hour of the Show"<<endl;
cin>>tvShow[i].Hour;
cout<<endl;
cout<<"Please enter the new minute the show airs"<<endl;
cin>>tvShow[i].Min;
cout<<endl;
}
}
}
void menu (Schedule tvShow[], int maxshows)
{
char user;

do
{
cout<<"This is the user menu"<<endl;
cout<<"Enter 'A' to add a show"<<endl;
cout<<"Enter 'D' to display a list of all shows"<<endl;
cout<<"Enter 'M' to modify a show's start time"<<endl;
cout<<"Enter 'Q' to quit the menu"<<endl;
cin>>user;
switch(user)
{
case 'a':
case 'A':
addShow(tvShow,maxshows);
break;
case 'd':
case 'D':
DisplayShow(tvShow,maxshows);
break;
case 'm':
case 'M':
ModifyShow(tvShow,maxshows);
break;
case 'q':
case 'Q':
cout<<"Bye :)"<<endl;
break;
default:cout<<"This is not one of the letters, Please try again"<<endl;
}
}while(user!='Q');
}

the programs stops working after you try to input a new show title

and another question
can do while loops work if the test condition has a compound statement because

do
{
cout<<"This is the user menu"<<endl;
cout<<"Enter 'A' to add a show"<<endl;
cout<<"Enter 'D' to display a list of all shows"<<endl;
cout<<"Enter 'M' to modify a show's start time"<<endl;
cout<<"Enter 'Q' to quit the menu"<<endl;
cin>>user;
switch(user)
{
case 'a':
case 'A':
addShow(tvShow,maxshows);
break;
case 'd':
case 'D':
DisplayShow(tvShow,maxshows);
break;
case 'm':
case 'M':
ModifyShow(tvShow,maxshows);
break;
case 'q':
case 'Q':
cout<<"Bye :)"<<endl;
break;
default:cout<<"This is not one of the letters, Please try again"<<endl;
}
}while(user!='Q');

this works but

do
{
cout<<"This is the user menu"<<endl;
cout<<"Enter 'A' to add a show"<<endl;
cout<<"Enter 'D' to display a list of all shows"<<endl;
cout<<"Enter 'M' to modify a show's start time"<<endl;
cout<<"Enter 'Q' to quit the menu"<<endl;
cin>>user;
switch(user)
{
case 'a':
case 'A':
addShow(tvShow,maxshows);
break;
case 'd':
case 'D':
DisplayShow(tvShow,maxshows);
break;
case 'm':
case 'M':
ModifyShow(tvShow,maxshows);
break;
case 'q':
case 'Q':
cout<<"Bye :)"<<endl;
break;
default:cout<<"This is not one of the letters, Please try again"<<endl;
}
}while(user!='Q'||user!='q');

doesnt

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.