aboutsummaryrefslogtreecommitdiff
path: root/CST116-Ch5-Debugging/CST116-Project1.cpp
diff options
context:
space:
mode:
authorMusa Ahmed <[email protected]>2022-10-06 13:05:07 -0700
committerMusa Ahmed <[email protected]>2022-10-06 13:05:07 -0700
commit5e895503bcaebcfcb4a4061b76b655c074d15fcf (patch)
tree0a423e68a24ec67172e141f92658b7150b8906df /CST116-Ch5-Debugging/CST116-Project1.cpp
parentMake sure gpa is decimal (diff)
downloadcst116-proj1-5e895503bcaebcfcb4a4061b76b655c074d15fcf.tar.xz
cst116-proj1-5e895503bcaebcfcb4a4061b76b655c074d15fcf.zip
gpa precision
Diffstat (limited to 'CST116-Ch5-Debugging/CST116-Project1.cpp')
-rw-r--r--CST116-Ch5-Debugging/CST116-Project1.cpp30
1 files changed, 8 insertions, 22 deletions
diff --git a/CST116-Ch5-Debugging/CST116-Project1.cpp b/CST116-Ch5-Debugging/CST116-Project1.cpp
index 11d3a2e..5c42eba 100644
--- a/CST116-Ch5-Debugging/CST116-Project1.cpp
+++ b/CST116-Ch5-Debugging/CST116-Project1.cpp
@@ -7,6 +7,7 @@
#include <list>
#include <bitset>
#include <vector>
+#include <math.h>
using namespace std;
using std::cout;
@@ -37,23 +38,6 @@ int main()
cout << "Enter a name: " << endl;
cin >> temp;
- /*
- while (isString == false) {
-
- for (int i = 0; temp[i]; i++) {
- if (isdigit(temp[i]) == false) {
- isString = true;
- break;
- }
- }
- if (isString = true) {
- break;
- }
-
- cout << "Please Enter a String!" << endl;
- cin >> temp;
- }
- */
n.push_back(temp);
@@ -79,8 +63,8 @@ int main()
cin >> temp;
}
- float val = (int)(stod(temp) * 100 + 0.5);
- gpa = (float)val / 100;
+ float val = roundf(stod(temp) * 100)/100;
+ gpa = val;
g.push_back(to_string(gpa));
cout << "Enter an income: " << endl;
@@ -89,11 +73,13 @@ int main()
}
+ cout << left << setfill('0') << gpa << endl;
+
for (int i = 0; i < 4; i ++) {
- cout << "Profile #" << i << ' ' <<
+ cout << "Profile #" << i+1 << ' ' <<
"Name: " << n[i] << ' ' <<
- "GPA: " << g[i] << ' ' <<
- "Income: " << c[i] << endl;
+ "Income: $" << c[i] << ' ' <<
+ "GPA: " << left << setfill('0') << setw(4) << g[i] << endl;
}
return 0;