problem with a "cin"

#include <iostream>
#include <string>
#include <conio.h>
#include <fstream>
#ifndef MUSEUM_H
#define MUSEUM_H

class Museum {
public:
void UsernamePassword();
void openFile();
void Counter();
}museo;

#endif
using namespace std;

struct money {
int kid;
int student;
int ID;
int adult;
int sc;
int kidcounter;
int studentcounter;
int idcounter;
int adultcounter;
int sccounter;
}rates;
int main() {
rates.kid=60;
rates.ID=54;
rates.student=60;
rates.adult=100;
rates.sc=80;
museo.UsernamePassword();
system("cls");
cout << "This is a Museum Ticket Counter\n"
<< "Reminders: Please input 'END' to go the next day\n"
<< "Here are the rates of the each division in age: \n"
<< "Kid/Toddler (Ages 1 to 10 years old)- Php60.00\n"
<< "Student - Php 60.00\n"
<< "Student (with current ID)- Php 54.00\n"
<< "Adult (Ages 19 to 64 years old)- Php 100.00\n"
<< "Senior Citizen (Ages 65 and above)- Php 80.00";
system("pause>0"); system("cls");
museo.Counter();
system("pause>0");
return 0;
}
void Museum::openFile() {
ofstream DataOutput;
DataOutput.open("file.txt", ios_base::app);
DataOutput << "Kids: " << rates.kidcounter << endl
<< "Students (without ID): " << rates.studentcounter << endl
<< "Students (with ID): " << rates.idcounter << endl
<< "Adults: " << rates.adultcounter << endl
<< "Senior Citizens: " << rates.sccounter << endl;
DataOutput.close();
}

void Museum::UsernamePassword() {
string newpassword;
int charLimit=20;
int n = 0;
char *pass = new char[20];
char character;
char username[100];


cout << "Username: ";
cin >> username[100];
cout << "Password: ";
do
{
character = _getch();
if (character == 8 && n >= 0)
{ // 1) priority: erase when backspace
if (n != 0)
{ // erase only if 1-more characters
cout << "\b \b";
n--;
} // else do nothing
}
else if (character == 13 && (n > 0 && n <= charLimit))
break; // 2) priority: accept intput when 1-20 characters
else if (n >= charLimit)
{ // 3) priority: when there are more than 20 characters
if (character == 13)
{ // once enter is pressed, prompt user else proceed
delete[]pass;
pass = new char[charLimit];
n = 0;
cout << "\n\t /!\\ Password has exceeded 20 characters. Please enter a new one.\n";
cout << "\tPassword: ";
}
}
if (character != 13 && character != 8)
{ // when input is not a special key
if (n < charLimit) // store when characters 1-20
pass[n] = character;
cout << "*"; // output asterisks and increment n regardless
n++;
}
} while (true);
// this flow will allow the user to input any # of characters
// but the program will ignore characters beyond the specified limit.
// still, asterisks will be displayed regardless of the character limit.
// the program will only prompt the user if the enter key was pressed.
cout << endl;
//to turn array of characters into string
for (int x = 0; x <= n - 1; x++)
newpassword += pass[x];
delete[]pass;
// return newpassword;
}

void Museum::Counter() {
system("pause>0");
string input;
int x=1,y=1, KID, STUDENT, IDs, ADULT, SC;
double total=0;
rates.kidcounter=0;
rates.studentcounter=0;
rates.idcounter=0;
rates.adultcounter=0;
rates.sccounter=0;


cout << "Day " << y << endl;
cout << "Customer " << x << endl;
cout << "Kids" << endl;
THE PROBLEM'S HERE --> cin >> KID;
cout << "Student (without ID) \n";
cin >> STUDENT;
cout << "Student (with ID) \n";
cin >> IDs;
cout << "Adults \n";
cin >> ADULT;
cout << "Senior Citizens \n";
cin >> SC;
total=KID*60 + STUDENT*60 + IDs*54 + ADULT*100 + SC*80;
cout << "Total Amount: " << total;
rates.kidcounter+=KID;
rates.studentcounter+=STUDENT;
rates.idcounter+=IDs;
rates.adultcounter+=ADULT;
rates.sccounter+=SC;
cin >> input;


if(input=="END") {
cout << "Thank you for using MR. Tan's Ticket Counter Program!";
exit(0);
}
else {
Museum::Counter();
y++; x++;
}


system("pause>0");
system("cls");
Museum::openFile();
}
you posted code, please use the code tags for your code

furthermore, you didn't ask anything, what's the problem?
my problem is way down in the last function
The cin>>KID; is not being processed by the compiler, only the other cin's except this one
Is there any way to resolve this?
#include <iostream>
#include <string>
#include <conio.h>
#include <fstream>
#ifndef MUSEUM_H
#define MUSEUM_H
//header files


class Museum {
public:
void UsernamePassword();
void openFile();
void Counter();
}museo;
//class declaration

#endif
using namespace std;

struct money {
int kid;
int student;
int ID;
int adult;
int sc;
int kidcounter;
int studentcounter;
int idcounter;
int adultcounter;
int sccounter;
}rates;
//structure declaration

int main() {
rates.kid=60;
rates.ID=54;
rates.student=60;
rates.adult=100;
rates.sc=80;
//declaration of rates
museo.UsernamePassword(); //calling of the UsernamePassword function
system("cls");
cout << "This is a Museum Ticket Counter\n"
<< "Reminders: Please input 'END' to go the next day\n"
<< "Here are the rates of the each division in age: \n"
<< "Kid/Toddler (Ages 1 to 10 years old)- Php60.00\n"
<< "Student - Php 60.00\n"
<< "Student (with current ID)- Php 54.00\n"
<< "Adult (Ages 19 to 64 years old)- Php 100.00\n"
<< "Senior Citizen (Ages 65 and above)- Php 80.00";
system("pause>0"); system("cls");
museo.Counter();//calling the function Counter
system("pause>0");
return 0;
}
void Museum::openFile() {
ofstream DataOutput;
DataOutput.open("file.txt", ios_base::app);
DataOutput << "Kids: " << rates.kidcounter << endl
<< "Students (without ID): " << rates.studentcounter << endl
<< "Students (with ID): " << rates.idcounter << endl
<< "Adults: " << rates.adultcounter << endl
<< "Senior Citizens: " << rates.sccounter << endl;
DataOutput.close();
} //function for making a file and storing the data

void Museum::Counter() {
system("pause>0");
string input;
int x=1,y=1, KID, STUDENT, IDs, ADULT, SC;
double total=0;
rates.kidcounter=0;
rates.studentcounter=0;
rates.idcounter=0;
rates.adultcounter=0;
rates.sccounter=0;
//declaration of variables

cout << "Day " << y << endl;
cout << "Customer " << x << endl;
cout << "Kids" << endl;

// here's my problem "cin >> KID;"
cin >> KID;


cout << "Student (without ID) \n";
cin >> STUDENT;
cout << "Student (with ID) \n";
cin >> IDs;
cout << "Adults \n";
cin >> ADULT;
cout << "Senior Citizens \n";
cin >> SC;
total=KID*60 + STUDENT*60 + IDs*54 + ADULT*100 + SC*80;
cout << "Total Amount: " << total;
rates.kidcounter+=KID;
rates.studentcounter+=STUDENT;
rates.idcounter+=IDs;
rates.adultcounter+=ADULT;
rates.sccounter+=SC;
cin >> input;


if(input=="END") {
cout << "Thank you for using MR. Tan's Ticket Counter Program!";
exit(0);
}
else {
Museum::Counter();
y++; x++;
}


system("pause>0");
system("cls");
Museum::openFile();
}
Last edited on
there is stilll no question...

try it like this: http://www.cplusplus.com/forum/articles/1295/
My problem is within the last function
the "cin >> KID;"
I've been searching for the past few hours but still haven't gotten a correct answer to get this fixed
Because every time i compile the codes, this line isn't executing
how do i resolve this problem?
What do you mean it isn't executing?
It's just like a pass-through
"cout << "Kids" << endl;" is being read then directly runs "cout << "Student (without ID) \n"; cin >> STUDENT;" but not running "cin >> KID;"
*the program isn't asking for my input for the number of kids
hm... that's odd...
what are your inputs?
Maybe the previous input were 2 variables and so cin just took the second one for KID
Topic archived. No new replies allowed.