c++ assistance needed for this project
<p>ok so i have just recently started doing programming in c++ with no experience of other languages.</p>

<p>i started out great with a simple minded idea for the school project but somehow it lost me in the code i was trying to create.</p>

<p>the idea is as follows, i want to create a program that first gives me a menu of "start" "load" "highscore" then as you choose one of them you get what it says :P so i started off with some basic struct to include the points i assign after each question to a .txt document then some if and switch-case and a do-while so if you fail you get choice to restart.</p>

<p>the code i have done so far( very far away from being complete but this is as far as i have gotten)(svar means answer / fraga mean question):</p>

<pre><code>    #include &lt;iostream&gt;
    #include &lt;fstream&gt;
    #include &lt;cstdlib&gt;
    using namespace std;

   struct highscore{
   int svar;
   }

   int main(){

bool fail = true;
int svar = 0, fraga;
char val;
do{
    cout &lt;&lt; " Menu" \n;
    cout &lt;&lt; " 1. Start" \n;
    cout &lt;&lt; " 2. Load" \n;
    cout &lt;&lt; " 3. Credits" \n;
    cin &gt;&gt; val;
    switch(val){

          case '1':
    ofstream utFil;
    utFil.open("highscore.txt", ios::app);
    if (!utFil){
    cout &lt;&lt; "file could not open";
    exit (1);
    }

                     cout &lt;&lt; "WELCOME TO THE CISCO QUIZ\n"  "GOOD LUCK\n \n \n" ;
                     cout &lt;&lt; "how many layers are there in the OSI model?" \n "4"\n   "5"\n "or 7?" \n;
                     cin &gt;&gt; fraga;
                     switch(fraga){
                                  case '4':

                                       cout &lt;&lt; "Game Over!"\n;
                                       cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes and 2 for no)\n";
                                       cin &gt;&gt; fail;
                                       if(fail != '1'){
                                               fail = false;
                                               }
                                       break;

                                  case '5':

                                       cout &lt;&lt; "Game Over!"\n;
                                       cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes, 2 for no)\n";
                                       cin &gt;&gt; fail;
                                       if(fail != '1'){
                                               fail = false;
                                               }
                                       break;

                                  case '7':
                                       svar = svar + 5;
                                       break;
                                       }

                                       if(svar == 5){
                                          cout &lt;&lt; "what is name full name of OSPF?" \n;
                                          cout &lt;&lt; "1. Open Shortest Path First" \n;
                                          cout &lt;&lt; "2. Online Shooting Pro Fishing" \n;
                                          cout &lt;&lt; "3. On Short Path First"\n ;
                                          cin &gt;&gt; fraga;
                                          switch(fraga){

                                                          case '1':
                                                          svar = svar + 5; 
                                                          }                                                                                  

                                                          case '2':
                                                               cout &lt;&lt; "Game Over!"\n;
                                                               cout &lt;&lt; "Do you wish to restart? (answer with yes, YES or Yes)"\n;
                                                               cin &gt;&gt; fail;
                                                               if(fail != '1'){
                                                               fail = false;
                                                                }
                                                               break;
                                                               }

                                                          case '3':
                                                               cout &lt;&lt; "Game Over!"\n;
                                                               cout &lt;&lt; "Do you wish to restart? (answer with yes, YES or Yes)"\n;
                                                               cin &gt;&gt; fail;
                                                                 if(fail != '1'){
                                                                     fail = false;
                                                                 }
                                                                 }
                                                                 }
                     if(svar == 10){
                     cout &lt;&lt; "What does TTL mean?" \n;
                     cout &lt;&lt; "1. Twin Twitched Life"\n;
                     cout &lt;&lt; "2. Two Time Lives"\n;
                     cout &lt;&lt; "3. Time To Live"\n;
                     cin &gt;&gt; fraga;                                  
                       switch(fraga){
                         case '1':
                          cout &lt;&lt; "Game Over!"\n;
                          cout &lt;&lt; "Do you wish to restart? (answer with yes, YES or Yes)"\n;
                          cin &gt;&gt; fail;
                           if(fail != '1'){
                           fail = false;
                           }
                         break;
                         }

                       case '2':
                         cout &lt;&lt; "Game Over!"\n;
                         cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes and 2 for no)"\n;
                         cin &gt;&gt; fail;
                          if(fail != '1'){
                          fail = false;
                          }
                       break;
                       }

                       case '3':
                       svar = svar + 10;
                       break;
                       }
                     }

                      if(svar == 20){
                              cout &lt;&lt; "What is the first command you enter on a Cisco router?"\n;
                              cout &lt;&lt; " 1. enable"\n;
                              cout &lt;&lt; " 2. disable"\n;
                              cout &lt;&lt; " 3. enter"\n;
                              cin &gt;&gt; fraga;

                              switch(fraga){
                                            case '1':
                                                 svar = svar + 5;
                                                 break;

                                            case '2':
                                                 cout &lt;&lt; "Game Over!"\n;
                                                 cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes and 2 for no)"\n;
                                                 cin &gt;&gt; fail;
                                                  if(fail != '1'){
                                                  fail = false;
                                                  }
                                                 break;
                                            case '3':
                                                 cout &lt;&lt; "Game Over!"\n;
                                                 cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes and 2 for no)"\n;
                                                 cin &gt;&gt; fail;
                                                  if(fail != '1'){
                                                  fail = false;
                                                  }
                                                 break;
                                                 }                                         
                                                 }

                                  if(svar == 25){
                                          cout &lt;&lt; "which protocol is the most prefered?"
                                          cout &lt;&lt; " 1. RIP"\n;
                                          cout &lt;&lt; " 2. EGRP"\n;
                                          cout &lt;&lt; " 3. EIGRP"\n;
                                          cin &gt;&gt; fraga;
                                          switch(fraga){
                                                        case '1':
                                                               cout &lt;&lt; "Game Over!"\n;
                                                               cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes and 2 for no)"\n;
                                                               cin &gt;&gt; fail;
                                                               if(fail != '1'){
                                                               fail = false;
                                                               }
                                                               break;
                                                               }    

                                                         case '2':
                                                              cout &lt;&lt; "Game Over!"\n;
                                                              cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes and 2 for no)"\n;
                                                              cin &gt;&gt; fail;
                                                               if(fail != '1'){
                                                                fail = false;
                                                                 }
                                                                break;
                                                                }  

                                                        case '3':
                                                             svar = svar + 15;
                                                             break;
                                                             }     
                                                             }

                            utFil.close();



    }        
    }
</code></pre>

<p>and as you can see this confuses me and probably you as well got any tips i will be very grateful</p>

<p>thx for help :></p>

<p>ok so since i have just joined this forum i am not allowed to answer my own question just yet so i have decided to update my original and send the code again but this time with another problem.This time i can not get the score to save into a .txt file it only creates a .txt but keeps it empty this is how the updated code looks like:</p>

<pre><code>    #include &lt;iostream&gt;
    #include &lt;fstream&gt;
    #include &lt;cstdlib&gt;
    using namespace std;
    struct highscore{

    int svar;
    };


    int main(){
ofstream highscore;            
bool fail = true;
int svar = 0, fraga, lost;
char val;
do{
    cout &lt;&lt; " Menu" &lt;&lt; endl;
    cout &lt;&lt; " 1. Start" &lt;&lt; endl;
    cout &lt;&lt; " 2. Load" &lt;&lt; endl;
    cout &lt;&lt; " 3. Credits" &lt;&lt; endl;
    cin &gt;&gt; val;
    switch(val){

          case '1':

                  highscore.open("Highscore.txt", ios::app);
                  if (!highscore){
                  cout &lt;&lt; "file could not open";
                  exit (1);

                  }


                     cout &lt;&lt; "WELCOME TO THE CISCO QUIZ  GOOD LUCK" &lt;&lt; endl;
                     cout &lt;&lt; "how many layers are there in the OSI model?" &lt;&lt; endl;
                     cout &lt;&lt; "1. 4" &lt;&lt; endl;
                     cout &lt;&lt; "2. 5" &lt;&lt; endl;
                     cout &lt;&lt; "3. 7" &lt;&lt; endl;
                     cin &gt;&gt; fraga;
                     switch(fraga){
                                  case 1:

                                       cout &lt;&lt; "Game Over!" &lt;&lt; endl;
                                       cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes and 2 for no)" &lt;&lt; endl;
                                       cin &gt;&gt; lost;
                                       if(lost == 2 ){
                                               fail = false;
                                               }
                                       break;

                                  case 2:

                                       cout &lt;&lt; "Game Over!" &lt;&lt; endl;
                                       cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes, 2 for no)" &lt;&lt; endl;
                                       cin &gt;&gt; lost;
                                       if(lost == 2 ){
                                               fail = false;
                                               }
                                       break;

                                  case 3:
                                       svar = svar + 5;
                                       break;
                                  default:
                                    cout &lt;&lt; "error" &lt;&lt; endl;
                                       }

                                       if(svar == 5){
                                          cout &lt;&lt; "what is the full name of OSPF?" &lt;&lt; endl;
                                          cout &lt;&lt; "1. Open Shortest Path First" &lt;&lt; endl;
                                          cout &lt;&lt; "2. Online Shooting Pro Fishing" &lt;&lt; endl;
                                          cout &lt;&lt; "3. On Short Path First" &lt;&lt; endl;
                                          cin &gt;&gt; fraga;
                                          switch(fraga){

                                                          case 1:
                                                          svar = svar + 5; 
                                                               break;                                                                             

                                                          case 2:
                                                               cout &lt;&lt; "Game Over!"&lt;&lt; endl;
                                                               cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes, 2 for no)" &lt;&lt; endl;
                                                               cin &gt;&gt; lost;
                                                               if(lost == 2 ){
                                                                  fail = false;
                                                                  }
                                                               break;


                                                          case 3:
                                                               cout &lt;&lt; "Game Over!" &lt;&lt; endl;
                                                               cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes, 2 for no)" &lt;&lt; endl;
                                                               cin &gt;&gt; lost;
                                                               if(lost == 2 ){
                                                                  fail = false;
                                                                 }
                                                                 }
                                                                 }

                     if(svar == 10){
                     cout &lt;&lt; "What does TTL mean?" &lt;&lt; endl;
                     cout &lt;&lt; "1. Twin Twitched Life" &lt;&lt; endl;
                     cout &lt;&lt; "2. Two Time Lives" &lt;&lt; endl;
                     cout &lt;&lt; "3. Time To Live" &lt;&lt; endl;
                     cin &gt;&gt; fraga;                                  
                       switch(fraga){
                         case 1:
                          cout &lt;&lt; "Game Over!" &lt;&lt; endl;
                          cout &lt;&lt; "Do you wish to restart? (answer with yes, YES or Yes)"&lt;&lt; endl;
                          cin &gt;&gt; lost;
                                  if(lost == 2 ){
                                     fail = false;
                                       }
                         break;


                       case 2:
                         cout &lt;&lt; "Game Over!" &lt;&lt; endl;
                         cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes and 2 for no)" &lt;&lt; endl;
                         cin &gt;&gt; lost;
                            if(lost == 2 ){
                                 fail = false;
                                     }
                       break;


                       case 3:
                       svar = svar + 10;
                       break;
                       }
                       }

                      if(svar == 20){
                              cout &lt;&lt; "What is the first command you enter on a Cisco router?" &lt;&lt; endl;
                              cout &lt;&lt; " 1. enable"&lt;&lt; endl;
                              cout &lt;&lt; " 2. disable" &lt;&lt; endl;
                              cout &lt;&lt; " 3. enter" &lt;&lt; endl;
                              cin &gt;&gt; fraga;

                              switch(fraga){
                                            case 1:
                                                 svar = svar + 5;
                                                 break;

                                            case 2:
                                                 cout &lt;&lt; "Game Over!" &lt;&lt; endl;
                                                 cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes and 2 for no)" &lt;&lt; endl;
                                                 cin &gt;&gt; lost;
                                                  if(lost == 2 ){
                                                       fail = false;
                                                               }
                                                 break;
                                            case 3:
                                                 cout &lt;&lt; "Game Over!" &lt;&lt; endl;
                                                 cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes and 2 for no)" &lt;&lt; endl;
                                                 cin &gt;&gt; lost;
                                                  if(lost == 2 ){
                                                     fail = false;
                                                                }
                                                 break;
                                                 }                                         
                                                 }

                                  if(svar == 25){
                                          cout &lt;&lt; "which protocol is the most prefered?" &lt;&lt; endl;
                                          cout &lt;&lt; " 1. RIP" &lt;&lt; endl;
                                          cout &lt;&lt; " 2. EGRP" &lt;&lt; endl;
                                          cout &lt;&lt; " 3. EIGRP" &lt;&lt; endl;
                                          cin &gt;&gt; fraga;
                                          switch(fraga){
                                                        case 1:
                                                               cout &lt;&lt; "Game Over!" &lt;&lt; endl;
                                                               cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes and 2 for no)" &lt;&lt; endl;
                                                               cin &gt;&gt; lost;
                                                                   if(lost == 2 ){
                                                                       fail = false;
                                                                                 }
                                                               break;


                                                         case 2:
                                                              cout &lt;&lt; "Game Over!"&lt;&lt; endl;
                                                              cout &lt;&lt; "Do you wish to restart? (answer with 1 for yes and 2 for no)" &lt;&lt; endl;
                                                              cin &gt;&gt; lost;
                                                               if(lost == 2 ){
                                                                    fail = false;
                                                                             }
                                                                break;


                                                        case 3:
                                                             svar = svar + 15;
                                                             break;
                                                        }
                                                 }                                                           

              highscore.close();                                                 

     case '2':
        cout &lt;&lt; "Still working on it" &lt;&lt; endl;
        break;

    case '3':
        cout &lt;&lt; "made by trickjay the most awesome guy on the planet!!!" &lt;&lt; endl;
        break;
    default:
     cout &lt;&lt; "Error try again" &lt;&lt; endl;



    }       
    }while(fail);
    }
</code></pre>

<p>how do i get my code to save the scores into a .txt file and not just create a .txt?</p>
