Making a presentation in C ++ (I'm stuck)

I am working on a school project (I'm in seventh grade) and why I want to be a programmer. I have to make an idea of ​​what a computer programmer is and what he does. I thought it would be nice to write my own presentation. I already encoded something, but I was stuck. This is what I still have

    #include <iostream>
    #include <string>

    using namespace std;

    int main()
    {
      string question;
      cout << "Type [1] to begin...";
      cin >> question;
      if(question == "1")
    {

      cout << "A computer programmer figures out the process of 
   designing, writing, testing, debugging, and maintaining the source c 
   ode for computer programs";   

         return 0;
     }

    }

Now, what I want to do is add an instruction like “goto”, where it can go to something like “int second ()” and cout something new like “what are programming languages?”. and then a description of what they do after the user enters something like yes. Any help would be greatly appreciated. I am really new to C ++. Thank:)

+4
source share
5

, codereview, , ( codereview)

. , :

#include <iostream>
#include <string>

using namespace std;

int main() {
    string question;
    cout << "Type [1] to begin...";
    cin >> question;
    if(question == "1") {

        cout << "A computer programmer figures out the process of
        designing, writing, testing, debugging, and maintaining the source c
        ode for computer programs";

        return 0;
    }
}

- IDE, IDE , , < img src= "https://i.stack.imgur.com/IhRE4.png" alt= " " > .


, .

, -, - , , , .

  • 1

, , ,

  1. , .
  2. , :

?

4b. , .

  1. , .
  2. ..

, , :

  • ,
  • , .

.

repeat, . repeat, , . ( youtube, ), do-while.

:

do {
    // Ask the user a question
    // Get the user input
    // validate the user input
    // if they want to see the slide show it
    // other wise, leave this loop
while (I have not run out of slides);

psuedo-code, :

#include <iostream>// cin, cout
#include <string>  // string
#include <vector>  // vector
#include <cstddef> // size_t

using namespace std;

int main() {
    vector<string> slides = {
            "A computer programmer figures out the process of"
            "designing, writing, testing, debugging, and maintaining the source c"
            "ode for computer programs",

            "what are programming languages?",

            // Add more here
    };

    size_t current_slide_index = 0;

    string user_response;

    do {
        cout << "Type [1] to continue: ";
        cin >> user_response;

        cin.ignore(100, '\n'); // This is used to skip to the next line

        if (user_response == "1") {
            cout << slides.at(current_slide_index) << std::endl;
        } else {
            break;
        }

    } while (++current_slide_index < slides.size());

    cout << "Happy learning\n";

    return 0;
}

  • vector, . ++. , .
  • cin >> -, . cin.ignore(100, '\n');

, codereview, , , , , https://codereview.stackexchange.com/.

+3

, :

#include <iostream>
#include <string>

using namespace std;

void q1()
{
    cout << "A computer programmer figures out the process of "
            "designing, writing, testing, debugging, and maintaining the source "
            "code for computer programs.\n";
}

void q2()
{
    cout << "what are programming languages? ...\n";
}

// void q3() ... ... ...

int main()
{
    string question = "1";
    cout << "Type [1] to begin... ([99] for quiting): ";

    cin >> question;

    /* while loop: http://en.cppreference.com/w/cpp/language/while */
    while (question != "99") {

        /* if statement: http://en.cppreference.com/w/cpp/language/if */
        if (question == "1") {
            q1();   // this is a "function call", you are invoking q1() 
        }

        else if (question == "2") {
            q2();
        }

        // else if(... q3() ... q4() ... and so on.

        /* read a new response for checking in the while condition */
        cout << "Next? ";
        cin >> question; 
    }

    return 0;

}
+2

goto , . SWITCH..CASE .

int main()
    {
      string question;
      label:
      cout << "Type [1,2,....] to begin...";
      cin >> question;
      if(question == "1")
    {

      cout << "A computer programmer figures out the process of designing, writing, testing, debugging, and maintaining the source code for computer programs" << endl;   
        goto label;

     }
     if(question == "2")
     {
         cout << " A programming language is a type of written language that tells computers what to do in order to work" << endl;
    }
0

, , , . , ++, , . , , , .

, , - , . .

  string question;
  cout << "Type [1] to begin...";
  cin >> question;

  cout << "A computer programmer figures out the process of 
     designing, writing, testing, debugging, and maintaining the source c 
     ode for computer programs";   

  cout << "Type [1] to continue...";
  cin >> question;

  cout << "Part 2";   


  return 0;
-2

: ++ - , , . ( , Science). ++, , . , C.

, , . .

C . CS, . .., C.
C , ++, .

: , . CS " " " ". State machine () : " , - ". . .. , . .

( ):

0) IO. : 1 :

 int input;

: const .

1) . Integer, output_string. , "1", ... "- (0) (1). 2) :    int state = 0; 3) : ( goto's. Loop goto)

while(scanf("%d", &input)){
   switch(state){
   case 0:
      switch(input){
       case 1:
       printf("A programmer blabla\n");
       state = 2;
       break;
       case 2:
       ...
      {
   break;
   case 1:
    ...
   case 10: // - last state
       switch(input){
       ...
       default:
       printf("goodbye");
       return 0; // terminate the program;
       }
   }
}

, Switch, printf() scanf(). .

, , , . .

-3

Source: https://habr.com/ru/post/1692798/


All Articles