CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2014
    Posts
    4

    Question and Answers Program

    //This is the only way I know that when a question is been asked it uses the statements below try it out.Only "Grade 1"I repeat Grade 1 only works at the moment for this is still a prototype.I am new to programming please bear with me.Thanks.

    #include<iostream>
    #include<string>
    using namespace std;
    using std::string;
    //functions
    int grade1(void);
    //questions
    int grade1q1(void);
    int grade1q2(void);
    int grade1q3(void);
    int grade2(void);
    int grade3(void);
    int grade4(void);


    int main()
    {
    string space ="\n\n\n\n\n\n\n\n\n\n\n\n\n";
    string line ="-------------------------------------------------------------------------------";
    int start;
    int grade;
    cout<<"Welcome to the English Guide.\nEnter (1)to continue or (0)to exit.\n\nAnswer:";
    cin>>start;
    if(start==1){


    do{
    cout<<"\n\nPlease Enter your Grade:\n";
    cout<<"\n[1]Grade 1\n\n[2]Grade 2\n\n[3]Grade 3\n\n[4]Grade 4\n\nAnswer:";
    cin>>start;
    }while(start<1||start>4);
    switch(start)
    {
    case 1:cout<<space<<line<<"\nGrade 1";cout<<grade1q1();cout<<grade1q2();cout<<grade1q3(); break;
    case 2:cout<<line<<"Grade 2"; break;
    case 3:cout<<line<<"Grade 3"; break;
    case 4:cout<<line<<"Grade 4"; break;
    default :cout<<line<<"Sorry This is number is not valid."; break;
    }
    }
    else cout<<"Thank you for using the English Guide";


    }

    int grade1q1(void)
    {
    int a1=0,a2,guessNum;
    cout<<"\n\nQuestion No.1\n\n";
    do
    {
    for (guessNum = 0;a1!= 1; guessNum++){
    if(guessNum<5){
    {

    cout<<"\n_____ you going to school?";
    cout<<"\n\n[1]Are [3]Is\n\n[2]They [4]Will\n";
    cin>>a1;
    }

    }else{cout<<"Thank you for using the program.";return 0;}
    }}while(a1!=1);

    }

    //Grade 1 Question 2
    int grade1q2(void)
    {
    int a1=0,a2,guessNum;
    cout<<"\n\nQuestion No.2\n\n";
    do
    {
    for (guessNum = 0;a1!= 4; guessNum++){
    if(guessNum<5){
    {

    cout<<"\n____ they be heading to the mall?";
    cout<<"\n\n[1]Are [3]Is\n\n[2]Them [4]Will\n";
    cin>>a1;
    }

    }else{cout<<"Thank you for using the program.";return 0;}
    }}while(a1!=4);
    }

    int grade1q3(void)
    {
    int a1=0,a2,guessNum;
    cout<<"\n\nQuestion No.3\n\n";
    do
    {
    for (guessNum = 0;a1!= 3; guessNum++){
    if(guessNum<5){
    {

    cout<<"\n____the dog jumping on the couch?";
    cout<<"\n\n[1]Are [3]Is\n\n[2]They [4]Will\n";
    cin>>a1;
    }

    }else{cout<<"Thank you for using the program.";return 0;}
    }}while(a1!=3);
    }

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Question and Answers Program

    Do you have a question?

    If you want help with code, you'll need to use code tags and proper formatting.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Question and Answers Program

    As GCDEF said, please use code tags when posting code. The code as posted is just about unreadable. Go Advanced, select the code and click '#'.

    Code:
    int grade1q1(void)
    {
    int a1 = 0,
         a2,
         guessNum;
    
         cout << "\n\nQuestion No.1\n\n";
        do
        {
            for (guessNum = 0; a1 != 1; guessNum++) 
            {
                 if (guessNum < 5) 
                 {
                      {
                            cout << "\n_____ you going to school?";
                            cout << "\n\n[1]Are [3]Is\n\n[2]They [4]Will\n";
                            cin >> a1;
                      }
                } 
                else 
                {
                      cout << "Thank you for using the program.";
                      return 0;
                }
           }
        } while (a1 != 1);
    }
    The extra braces highlighted are not needed.
    Code:
    using namespace std;
    using std::string;
    You don't need to have using std::string as you already have using namespace std.

    Code:
    case 1:cout<<space<<line<<"\nGrade 1";cout<<grade1q1();cout<<grade1q2();cout<<grade1q3(); break;
    I would advise against having more than one statement per line
    Code:
    case 1:
         cout << space << line <<" \nGrade 1";
         cout << grade1q1();
         cout << grade1q2();
         cout << grade1q3();
         break;
    Code:
    string space ="\n\n\n\n\n\n\n\n\n\n\n\n\n";
    string line ="-------------------------------------------------------------------------------";
    As the value of these variables doesn't change, they would usually be defined as const.
    Code:
    const string space ="\n\n\n\n\n\n\n\n\n\n\n\n\n";
    const string line ="-------------------------------------------------------------------------------";
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured