Here is an example with a simple Console Program I made:
1: #include <iostream>
2: #include <iomanip>
3: #include <string>
4:
5: using namespace std;
6:
7: int main()
8: {
9: //** Declarations **
10: double hourpay, twoweeks, month, year;
11: int ans, weeksWorked;
12: string name;
13: bool flag = false;
14:
15: cout << "Welcome to the Budget Console" << endl;
16: cout << endl;
17: cout << "Please enter your name: ";
18: getline(cin, name);
19: system("cls");
20:
21: cout << name << ", How much do you earn per hour: ";
22: cin >> hourpay;
23: cout << endl;
24: cout << "How much do you work in a week: ";
25: cin >> weeksWorked;
26: cout << endl;
27: system("cls");
28:
29: //** Menu **
30: while (!flag)
31: {
32: cout << "\t Menu" << endl;
33: cout << "1) Calculate how much I earn in 2 weeks."<< endl;
34: cout << "2) Calculate how much I earn in a month."<< endl;
35: cout << "3) Calculate how much I earn in a year: ";
36: cin >> ans;
37: cout << endl;
38:
39: //** Calculation **
40: twoweeks = hourpay * weeksWorked;
41: month = twoweeks * 2;
42: year = (twoweeks * 2) * 12;
43:
44: //** Outputs **
45: if (ans == 1) {
46: cout << "Your Two Weeks Pay: $" << twoweeks << ".00 " << endl;
47: flag = true;
48: }
49: else if (ans == 2) {
50: cout << "Your a month Pay: $" << month << ".00 " << endl;
51: flag = true;
52: }
53: else if (ans == 3) {
54: cout << "Your a month Pay: $" << year << ".00 " << endl;
55: flag = true;
56: }
57: else {
58: cout << "Invalid Selection" << endl;
59: }
60: }
61: system("pause");
62: return 0;
63: }
I like it. I'll have to change the other posts of mine to use this.
ReplyDelete