Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7.  
  8. //Variables
  9. string grade = "";
  10. double value = 0.0;
  11. bool valid = true;
  12.  
  13. //Input
  14. cout << "Enter a grade: " << endl;
  15. cin >> grade;
  16.  
  17.  
  18. //Validation
  19. if (!(grade.substr(0, 1) == "A" || grade.substr(0, 1) == "B" || grade.substr(0, 1) == "C" || grade.substr(0, 1) == "D" || grade.substr(0, 1) == "F"))
  20. {
  21. valid = false;
  22. }
  23.  
  24. else if (grade.length() > 2)
  25. {
  26. valid = false;
  27. }
  28.  
  29. else if (grade.length() == 2)
  30. {
  31. if (grade.substr(1, 1) != "+" || grade.substr(1, 1) != "-")
  32. {
  33. valid = false;
  34. cout << "stuff" << endl;
  35. }
  36. }
  37.  
  38. //Assigning value to grade
  39. if (valid == true){
  40. if (grade.substr(0, 1) == "A"){
  41. value = 4.0;
  42. }
  43.  
  44. else if (grade.substr(0, 1) == "F"){
  45. value = 0.0;
  46. }
  47.  
  48. else if (grade.substr(0, 1) == "B"){
  49. value = 3.0;
  50. }
  51.  
  52. else if (grade.substr(0, 1) == "C"){
  53. value = 2.0;
  54. }
  55.  
  56. else if (grade.substr(0, 1) == "D"){
  57. value = 1.0;
  58. }
  59.  
  60. // + or -
  61. if (grade.substr(1, 1) == "+"){
  62. value += 0.3;
  63. }
  64.  
  65. else if (grade.substr(1, 1) == "-"){
  66. value -= 0.3;
  67. }
  68. }
  69.  
  70. //Output
  71. if (valid == false){
  72.  
  73. cout << "Input is invalid." << endl;
  74.  
  75.  
  76. }
  77. else if (valid == true){
  78. cout << "Numeric value: " << value << endl;
  79. }
  80.  
  81. //Other
  82. system("pause");
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement