Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- string fullName;
- double grade, age;
- string inputFullName()
- {
- cout << " Enter your full name: ";
- getline(cin >> ws, fullName);
- if (fullName.size() < 2)
- {
- cout << "\n";
- cout << " Your name should contain at least 2 letters!" << "\n" << "\n";
- return inputFullName();
- }
- return fullName;
- }
- int inputGrade()
- {
- cout << " Enter a grade: ";
- cin >> grade;
- if (grade < 2 && grade > 6)
- {
- return inputGrade();
- }
- return grade;
- }
- int inputAge()
- {
- cout << " Enter your age: ";
- cin >> age;
- if (age < 0)
- {
- return inputAge();
- }
- return age;
- }
- int gradeInt()
- {
- cout << setiosflags(ios::fixed) << setprecision(2);
- grade = round(grade);
- int gradeInt = grade;
- return gradeInt;
- }
- int ageInt()
- {
- cout << setiosflags(ios::fixed) << setprecision(2);
- age = round(age);
- int ageInt = age;
- return ageInt;
- }
- int main()
- {
- inputFullName();
- cout << "\n";
- inputAge();
- cout << "\n";
- inputGrade();
- cout << "\n \n \n";
- cout << " Name: " << fullName << "\n";
- cout << " Age: " << ageInt() << "\n";
- cout << " Grade: " << gradeInt() << "\n";
- cout << "\n" << "\n";
- string repeat;
- cout << " If you want to repeat, type one of these: YES, Yes/yes, Y/y." << "\n";
- cout << " If not, type: NO, No/no, N/n." << "\n" << "\n";
- cout << " Your answer is: ";
- cin >> repeat;
- for (int i = 0; i < repeat.length(); i++)
- {
- repeat[i] = tolower(repeat[i]);
- }
- if (repeat == "yes" || repeat == "y")
- {
- cout << "\n" << "\n";
- main();
- }
- else if (repeat == "no" || repeat == "n")
- {
- return 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment