aboutsummaryrefslogtreecommitdiff
path: root/CST116-Ch5-Debugging
diff options
context:
space:
mode:
authorMusa Ahmed <[email protected]>2022-10-05 21:41:04 -0700
committerMusa Ahmed <[email protected]>2022-10-05 21:41:04 -0700
commit784303464472777922b7bc1b68b5134a9808b78c (patch)
treea999550b767deba104bee73aff62daea38fb8509 /CST116-Ch5-Debugging
parent. (diff)
downloadcst116-proj1-784303464472777922b7bc1b68b5134a9808b78c.tar.xz
cst116-proj1-784303464472777922b7bc1b68b5134a9808b78c.zip
Make sure gpa is decimal
Diffstat (limited to 'CST116-Ch5-Debugging')
-rw-r--r--CST116-Ch5-Debugging/CST116-Project1.cpp67
1 files changed, 55 insertions, 12 deletions
diff --git a/CST116-Ch5-Debugging/CST116-Project1.cpp b/CST116-Ch5-Debugging/CST116-Project1.cpp
index d45c035..11d3a2e 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>
+
using namespace std;
using std::cout;
using std::cin;
@@ -20,38 +21,80 @@ int main()
vector<string> n;
vector<string> g;
vector<string> c;
+
+
+
+ float gpa;
string temp;
for (int i = 0; i < 4; i++) {
+
+ bool isDecimal = false;
+ bool isString = false;
+
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);
- cout << "Enter a gpa: " << endl;
+
+
+ cout << "Enter a decimal gpa: " << endl;
cin >> temp;
- g.push_back(temp);
+
+ while (isDecimal == false) {
+
+ for (int i = 0; temp[i]; i++) {
+ if (temp[i] == '.') {
+ isDecimal = true;
+ break;
+ }
+
+ }
+ if (isDecimal == true) {
+ break;
+ }
+
+ cout << "Please enter a Decimal!" << endl;
+ cin >> temp;
+ }
+
+ float val = (int)(stod(temp) * 100 + 0.5);
+ gpa = (float)val / 100;
+ g.push_back(to_string(gpa));
+
cout << "Enter an income: " << endl;
cin >> temp;
c.push_back(temp);
}
+
for (int i = 0; i < 4; i ++) {
cout << "Profile #" << i << ' ' <<
- "Name: " << n[i] << ' ' <<
- "GPA: " << g[i] << ' ' <<
- "Income: " << c[i] << endl;
+ "Name: " << n[i] << ' ' <<
+ "GPA: " << g[i] << ' ' <<
+ "Income: " << c[i] << endl;
}
return 0;
-
-
-
-
-
-
-
} \ No newline at end of file