How to update program while running

+1 jenson francis · February 11, 2015
im creating a program where i have to update certain positions with respect to the upcoming years as posts change every year.
this is my code only using if statements
#include<iostream.h>
#include<conio.h>
int main()
{ int choice,choice1;
    
    cout<<"enter the year to which you want information to"
       <<"01-02\n"
       <<"02-03\n"
       <<"03-04\n"
       <<"04-05\n"
       <<"05-06\n"
       <<"06-07\n"
       <<"07-08\n"
       <<"08-09\n"
       <<"09-10\n"
       <<"10-11\n"
       <<"11-12\n"
       <<"12-13\n"
       <<"13-14\n";
       cin>>choice;
       if(choice==01)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ;
            cout<<"enter your choice";
            cin>>choice1;         
             if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             if(choice==02)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ;
            cout<<"enter your choice";
             cin>>choice1;        
             {if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             }
             if(choice==03)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ;  
            cout<<"enter your choice";
             cin>>choice1;       
             {if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             }
             if(choice==04)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ;
            cout<<"enter your choice";
             cin>>choice1;         
             {if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             }
             if(choice==05)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ; 
              cout<<"enter your choice";
             cin>>choice1;      
             {if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             }
             if(choice==06)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ;
             cout<<"enter your choice";
             cin>>choice1;        
             {if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             }
             if(choice==07)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ;
            cout<<"enter your choice";
             cin>>choice1;         
             {if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             }
             if(choice==8)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ;
            cout<<"enter your choice";
             cin>>choice1;         
             {
             if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             }
             if(choice==9)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ;
             cout<<"enter your choice";
             cin>>choice1;        
             {if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             }
             if(choice==10)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ;
             cout<<"enter your choice";
             cin>>choice1;        
             {if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             }
             if(choice==11)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ; 
             cout<<"enter your choice";
             cin>>choice1;       
             {if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             }
             if(choice==12)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ; 
             cout<<"enter your choice";
             cin>>choice1;       
             {if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             }
             if(choice==13)
       {cout<<"1.headboy\n"
            <<"2.headgirl\n"
            <<"3.topper\n" ;
             cout<<"enter your choice";
             cin>>choice1;        
             {if(choice1==1)
             cout<<"ankit nagar";
             else if(choice1==2)
             cout<<"anmol kaushik";
             else
             cout<<"ashutosh";
             }
             }
             getch();
             return 0;
             }
now what should i do if i want to increase the years and people associates with it during execution

Post a Reply

Replies

Oldest  Newest  Rating
+1 Abdullah Nauman · February 11, 2015
Please Please Please, formate your code, and put it inside the code tags. How do you expect us to read your 1,000,000 lines of unformatted code and help you. 
+1 Jay Deshaun · February 12, 2015
You should use a "switch" statement!
#include<iostream.h>
#include<conio.h>
int main(){
int choice,choice1;
cout<<"Enter the year to which you want information to"
<<"01-02\n"
<<"02-03\n"
<<"03-04\n"
<<"04-05\n"
<<"05-06\n"
<<"06-07\n"
<<"07-08\n"
<<"08-09\n"
<<"09-10\n"
<<"10-11\n"
<<"11-12\n"
<<"12-13\n"
<<"13-14\n";
cin>>choice;
switch(choice){
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
break;
case 11:
break;
case 12:
break;
case 13:
break;
}
cout<<"1.Headboy\n 2.Headgirl\n 3.Topper\n Enter Your Choice";
cin>>choice1;
if(choice1==1)
cout<<"ankit nagar";
else if(choice1==2)
cout<<"anmol kaushik";
else
cout<<"ashutosh";

getch();
return 0;
}
0 Abdullah Nauman · February 12, 2015
Yes  thank you jay. That code is a lot more readable. 
0 Jay Deshaun · February 12, 2015
No problem, but I changed most of it out because it could be put into a switch statement and the cases are the same so I just left them blank and put the original little script at the end of the switch statement so that @Jenson could figure out what they're trying to do.
0 jenson francis · February 14, 2015
thanx jay this made it much more legible but is it possible to use arrays in this case my teacher wants it to be a little more complex
0 jenson francis · February 14, 2015
the question i asked hasnt got an answer to it , how am i to update a running program??
0 Jay Deshaun · February 14, 2015
You could use an array but it would still require the switch statement and there would be no reason to use an array.
+1 Abdullah Nauman · February 17, 2015
I don't thing there is a way to update a program while its running. Because the compiler takes your code, converts it to binary(which is stored in another file), and then runs it, there is no way to load something while the program is running, you would have to relauch it because at the time the program launched before, the updated code you added was not even there. I am not really sure if all this makes sense, but what you could do is temporarily create a backdoor in the program, just remember to close it up though.
0 Jason Amador · February 17, 2015
Dynamic array or vector of "roster" objects that contain the three positions and the person filling them.  And I guess maybe a year offset, so that you can get to the elements easily.  e.g. element 0 should represent the year 2001, so offset would be 1.  Then you can add dynamically allocated objects to the vector at run time.  This stuff is somewhat advanced, so I would just say look into dynamic memory allocation for this question.
0 jenson francis · February 18, 2015
thanx jason i am a newbie at c++ i will try my best to understand it
  • 1

C++

107,131 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator