help for a beginner

need help im a beginner in c++ this is part of the code in our midterm exam
why does it close after i input the name of the professor
feedback is appreciated thanks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include<iostream>

using namespace std;

int main()

{
   int a, b;

    cout<<"Enter name of Professor: \n";
    cin>>a;

    cout<<"Enter Level Code: \n";
    cin>>b;
    
    
    
   ("pause");
    return 0;
    
} 
use system ("pause");
where do you put it?

i was using that code in visual c++ does it require system("pause"); too??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
#include <cstdlib>

int main()
{
    std::string name ;
    std::cout << "Enter name of Professor (wthout spaces): " ;
    std::cin >> name ; // read the name into a string

    int level_code ;
    std::cout << "Enter Level Code: " ;
    std::cin >> level_code ; // // read the level code into an int

    std::cout << "You entered name: " << name << "  level code: " << level_code << '\n' ;

    std::system( "pause" ) ;
}
Also, you are asking someone to input a name, which is a series of characters called a "string", into an integer variable. JL has ya fixed for that problem though.
i tried what you did. but can you do it revising mine using just declaring variable a as string and b as int. without those std's
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
#include<string>
#include <cstdlib>

using namespace std;

int main()

{
    string a;
    int b;
    cout<<"Enter name of Professor: \n";
    cin>>a;

    cout<<"Enter Level Code: \n";
    cin>>b;
    system("pause");
    return 0;

}
use getline (cin, a) as cin>>a will only store a character.
Last edited on
Topic archived. No new replies allowed.