Cannot make goto, and just end the program by itself

How to correct this one please?
can't make solutions to it. I made a program that will covert temperature,

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <cstring>
#include <conio.h>
using namespace std;
        char again[10];
        char yes[10]="Yes";
        char no[10]="No";
        char temp[20];
        char user[20]="Celsius";
        char user1[20]="Fahrenheit";

int main()

{
    start:
cout<<"\n*******************************************\n";
cout<<"\t\"Temperature Converter\"";
cout<<"\n*******************************************\n\n\n";
temp:
cout<<"What Temperature you had?"<<endl;
cout<<"And we'll convert it to the different kinds of Temperature..."<<endl;
cin.get(temp,20);

if (strcmp(user,temp)==0)
{
    int cel;
    int far;
    cout<<"\n\nObviously, you're looking for the Fahrenheit conversion of it?\n";
    cout<<"Type the Celsius:\n";
    cin>>cel;
    far=cel*9/5+32;
    cout<<"Fahrenheit is ";
    cout<<far<<"°";

}

else if (strcmp(user1,temp)==0)
{
    int cels;
    int fahr;
    cout<<"\n\nObviously, you're looking for the Celsius conversion of it?\n";
    cout<<"Type the Fahrenheit:\n";
    cin>>fahr;
    cels=(fahr-32)*5/9;
    cout<<"Celsius is ";
    cout<<cels<<"°";
}

else
{
    cout<<"Invalid Input!";
    goto again1;
}

{
    again1:

        cout<<"\n\nStart again? [Yes/No]\n";
        cin.get(again,10);
        if (strcmp(no,again)==0)
        {
            goto start;
        }
        else if (strcmp(yes,again)==0)
        {
            goto exit;
        }
}
exit:
getch();
return 0;
}



And in this part, Can't type the Yes or No, cin not processing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
    again1:

        cout<<"\n\nStart again? [Yes/No]\n";
        cin.get(again,10);
        if (strcmp(no,again)==0)
        {
            goto start;
        }
        else if (strcmp(yes,again)==0)
        {
            goto exit;
        }
}


This, when the program starts to ask the user
"Start again?"
and when I type anything(Just 1 character), it ends up automatically
 
        cin.get(again,10);



Can someone help me with this one? Can't finish eey. Thank you in advance :)
Up^
The get function and the >> operator does not discard the newline character at the end of the line so when you call get next time you will find the same newline character again, as the first character, making the input string empty.

There are many ways you can go about this, but one of the easiest is to call cin >> ws; before each call to get to ensure that all whitespace characters (which includes newlines) are discarded before get is called.

http://www.cplusplus.com/reference/istream/ws/
Last edited on
Topic archived. No new replies allowed.