C++, cin.get() fungerar inte :S
Skrev ett litet program för att testa på klasser och fått allt att fungera som det ska, förutom att cin.get() inte fungerar för att pausa programmet. Te.x system ("pause") eller cin >> age fungerar utmärkt, så då undrar jag varför cin.get() inte fungerar. Sitter med Visual C++ Express 2010 och måste ha något avbrott i programmet så att terminalfönstret försvinner innan jag hunnit se outputen.
Är det något i koden som ser fult ut och skulle kunnas göras bättre så lyssnar jag gärna på tips.
Employee.h
typedef unsigned short USHORT;
class Employee{
public:
Employee(USHORT initial_age, USHORT intial_years_of_service, double initial_salary);
~Employee();
void SetAge(USHORT new_age) { age = new_age; } //for setting the new age
USHORT GetAge() { return age; } //for showing the private age
void SetYearsOfService(USHORT new_years_of_service) { years_of_service = new_years_of_service; }
USHORT GetYearsOfService() { return years_of_service; }
void SetSalary(double new_salary) { salary = new_salary; } //for setting the new private salary
double GetSalary() { return salary; } //for showing the private salary
private:
USHORT age;
USHORT years_of_service;
double salary;
};
Employee::Employee(USHORT initial_age, USHORT initial_years_of_service, double initial_salary){ //declaring the privates
age = initial_age;
years_of_service = initial_years_of_service;
salary = initial_salary;
}
Employee::~Employee(){
}
Main.cpp
#include "Employee.h"
#include <iostream>
using std::cin;
using std::cout;
int main(){
USHORT age;
USHORT years_of_service;
double salary = 0;
USHORT years_that_have_passed;
double procentage;
cout << "Enter the employees age: ";
cin >> age;
cout << "\nEnter the number of years the employee has been in service: ";
cin >> years_of_service;
cout << "\nEnter the employees yearly salary($): ";
cin >> salary;
cout << "\nEnter the employees salary increase (%): ";// 1.04 = 4%, 4 = 400%.
cin >> procentage;
cout << "\nHow many years do you want to pass? ";
cin >> years_that_have_passed;
cout << "\n";
Employee OnlyOne(age, years_of_service, salary); //sets values
for(USHORT i = 0; i < years_that_have_passed; i++){ //loop for increasing values during the passing years
cout << "\nEmployees age: " << OnlyOne.GetAge();
cout << "\nNumber of years the employee has been in service: " << OnlyOne.GetYearsOfService();
cout << "\nEmployees yearly salary: " << OnlyOne.GetSalary();
cout << "\n";
salary = salary * procentage; //increases the yearly salary
years_of_service++;
age++;
OnlyOne.SetAge(age);
OnlyOne.SetYearsOfService(years_of_service);
OnlyOne.SetSalary(salary);
}
cin.get(); // system("pause") || cin >> age works! :S
return 0;
}
4690K, 16GB ram, 1,25TB SSD, Radeon 7750
100% PASSIVT