fork download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. double score[5];
  6. int count = 0;
  7. while(count < 5)
  8. {
  9. std::cout << "Enter a number:\n";
  10. double temp;
  11. if(std::cin >> temp)
  12. {
  13. // Got a double now check the range
  14. if (temp > 0 && temp < 100)
  15. {
  16. // Checked out, store in array
  17. score[count++] = temp;
  18. }
  19. else
  20. {
  21. std::cout << "Value not between 0 and 100\n";
  22. continue;
  23. }
  24. }
  25. else
  26. {
  27. std::cout << "Invalid entry\n";
  28. std::cin.clear();
  29. std::cin.ignore();
  30. }
  31. }
  32. std::cout << "\nPrinting contents:\n";
  33. for (int i = 0; i < 5; ++i)
  34. std::cout << score[i] << ' ';
  35. }
  36.  
  37.  
Success #stdin #stdout 0s 2964KB
stdin
1
a
2
3

?
4
....
5
stdout
Enter a number:
Enter a number:
Invalid entry
Enter a number:
Enter a number:
Enter a number:
Invalid entry
Enter a number:
Enter a number:
Invalid entry
Enter a number:
Invalid entry
Enter a number:

Printing contents:
1 2 3 4 5