I'm having a problem on try again program.I checked the syntax and yet is still not working.am trying to make a program that will output the student's grade and when the program is finished it will ask whether to try again or not.If the input is y or Y, the program will repeat all over again.

p.s:it must be on do while loop on choice 4.

Here's the code:

#include <iostream>
using namespace std;
main()
   {   
      const int size=4;
      int choice[size];
      int q1,q2,qT,exam,stand;
      double ave;
      char exit,again;
      char y,n;
   
      
      cout<<"Grade Computation"<<endl;
      cout<<"Select Choice:"<<endl;
      cout<<"1.Prelim Grade"<<endl;
      cout<<"2.Midterm Grade"<<endl;
      cout<<"3.Final Grade"<<endl;
      cout<<"4.Exit"<<endl;
      cout<<endl;
      system("pause");
      cout<<"Enter choice[1-4]:";
      cin>>choice[size];
 do
 {   
      switch(choice[size])
      {
                          case 1:
                               cout<<"Enter Quiz 1:";
                               cin>>q1;
                               cout<<"Enter Quiz 2:";
                               cin>>q2;
                               
                               qT=q1+q2;
                               qT=qT / 2;
                               
                               cout<<endl<<"Quiz Average:"<<qT;
                               cout<<endl<<"Prelim Exam:";
                               cin>>exam;
                               cout<<"Class Standing:";
                               cin>>stand;
                               
                               ave=qT *.40 + stand *.10 + exam *.50;
                               
                               cout<<endl<<"Prelim Grade:"<<ave;
                               cout<<endl<<"Try again?[y/n]:";
                               cin>>again;
                               while(again=='y')
                               {
                                  cin>>choice[size];
                               }                
                                   if(again=='n')
                                                 cout<<"goodbye!!";             
                               break;
                               
                           case 2:
                               cout<<"Enter Quiz 1:";
                               cin>>q1;
                               cout<<"Enter Quiz 2:";
                               cin>>q2;
                               
                               qT=q1+q2;
                               qT=qT / 2;
                               
                               cout<<endl<<"Quiz Average:"<<qT;
                               cout<<endl<<"Midterm Exam:";
                               cin>>exam;
                               cout<<endl<<"Class Standing:";
                               cin>>stand;
                               
                               ave=qT *.40 + stand *.10 + exam *.50;
                               
                               cout<<endl<<"Midterm Grade:"<<ave;
                               cout<<endl<<"Try again?[y/n]:";
                               cin>>again;
                               while(again=='y')
                               {
                                  cin>>choice[size];
                               }                
                                   if(again=='n')
                                                 cout<<"goodbye!!";   
                               
                               break;
                           
                            case 3:
                               cout<<"Enter Quiz 1:";
                               cin>>q1;
                               cout<<"Enter Quiz 2:";
                               cin>>q2;
                               
                               qT=q1+q2;
                               qT=qT / 2;
                               
                               cout<<endl<<"Quiz Average:"<<qT;
                               cout<<endl<<"Midterm Exam:";
                               cin>>exam;
                               cout<<endl<<"Class Standing:";
                               cin>>stand;
                               
                               ave=qT *.40 + stand *.10 + exam *.50;
                               
                               cout<<endl<<"Midterm Grade:"<<ave;
                               cout<<endl<<"Try again?[y/n]:";
                               cin>>again;
                               system("pause");
                               while(again=='y')
                               {
                                  cin>>choice[size];
                               }                
                                   if(again=='n')
                                                 cout<<"goodbye!!";   
                               
                               break;
                        
                            case 4:
                                 cout<<"Are you sure you want to exit[y/n]:";
                                 cin>>exit;                                      
}        
                                 while(exit=='n');
                                               cout<<"goodbye!";
                              break;
                              

                              
                                 
                               
      }                
                             
      

}

SO what do you want included in the loop? Point to the line that needs to be inside to loop that isn't already.
Finish your do-while loop.

In fact, start over. Get the program running in small pieces, stop trying to write the whole thing and clean up the problems later.
1) Start by writing the loop. Input the Y/N and continue or not based on the input.
2) Next, add the menu. Make sure it still loops properly.
3) Add the switch statement. Test it again....

Programming this way is faster and you understand each piece much better.

Edited 5 Years Ago by WaltP: n/a

Comments
Thanks,i'll try
This article has been dead for over six months. Start a new discussion instead.