I can't use gets() function like i want

Hello,

It's a personal medicine tracking program. I write like this program to improve my c++ skill. Program run rightly at first running it ask medicine name, it's total number that i have, and number that i receive daily. According to these it says when medicine will finish. But first loop is right after first loop program don't ask me medicine name. So i can't medicine's name twice or more. where are my fault?

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
74
75
76
77
78
79
80
81
82
83
84
  typedef unsigned short int ushort;
#include <iostream>
#include <fstream>
using namespace std;

class medicine
{
      ushort number,day;
      public:
             char name[20];
             void receivenumber(ushort itsnumber);
             void receiveday(ushort number);
             ushort writenumber(){ return number;}
             ushort writeday(){ return day;}

             
      }tracking; 
      
void medicine::receivenumber(ushort itsnumber)
             {
                  number=itsnumber;
                  }
void medicine::receiveday(ushort number)
             {
                  day=number;
                  }
void Menu();
void receive();
void write();
int main()
{
    Menu();
    system("PAUSE");
    return 0;
    }

void Menu()
{
     ushort itsnumber,number,result,vary=0,continuum,loop=0;
     while(!loop)
     {
     cout<<"write the medicine name\n";
     gets(tracking.name);
     cout<<"write this medicine's number that you have\n";
     cin>>itsnumber;
     tracking.receivenumber(itsnumber);
     cout<<"write this medicine's number that you need receive daily\n";
     cin>>number;
     tracking.receiveday(number);
     result=tracking.writenumber()/tracking.writeday();
     cout<<"\t";
     write();
     cout<<" medicine will finish after"<<result<<" day\n"; 
     ofstream dosya("tracking.txt");
                             if(!dosya){
                               cerr<<"File doesn't open!!!"<<endl;
                               exit(1);
                               }
                               while(!vary)
                               {
                                             dosya<<"\n\n              medicine's name                 number                      remain day\n";
                                             dosya<<"---------------------------------------------------------------------------\n";
                                             dosya<<"---------------------------------------------------------------------------\n";
                                             dosya<<"              ";
                                             dosya<<tracking.name;
                                             dosya<<"                   "<<tracking.writenumber();
                                             dosya<<"                         "<<result<<endl;
                                             vary=1;
                                             }
     cout<<"\tto add another medicine press 1 to exit press 0\n";
     cin>>continuum;
     if(continuum==1)
       loop=0;
     else if(continuum==0)
       exit(1);
       }
}
void write()
{
     ushort i;
     for(i=0;i<=strlen(tracking.name);i++)
       cout<<tracking.name[i];
     }
Last edited on
try putting cin.ignore after cin >> continuum;
thanks it works
Topic archived. No new replies allowed.