Help with strings.

closed account (zwpL3TCk)
Hi! I'm new in c++ and having a hard time with string. When i put a space, only the last word will print out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <cstdlib>
#include <stdio.h>
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    string name;
    string section;
    string course;
    cout << "\nFull Name: ";
    cin >> name;
    getline(cin,name);
    cout << "Section: ";
    cin >> section;
    getline(cin,section);
    cout << "Course: " ;
    cin >> course;
    cin.ignore ();
    
    if((course == "BSCS") || (course == "bscs") || (course == "BSIT") || (course == "bsit") || (course == "ACT") || (course == "act")){
    cout << "\nPlease wait";
    Sleep(1000);
    cout << ".";
    Sleep(1000);
    cout <<".";
    Sleep(1000);
    cout << ".";
    Sleep(1000);
    system ("cls");
}
     else{
     cout << "\nSorry! Student from another department is prohibited to play the Quiz Master.";
}
    cout << "\n\t\t\t   Hi," << name << "\n\t\t\tWelcome to the Quiz Master!\n";
    getchar();
    return 0;
}

Remove line 14, you are reading name twice (also on line 15).
closed account (zwpL3TCk)
i tried to remove line 14 but after i put a name with space, nothing happens.

EDIT:

Thank you! it works now! :)
Last edited on
Topic archived. No new replies allowed.