fork download
  1. //@Author Damien Bell
  2. #include <iostream>
  3. #include <iomanip>
  4. using namespace std;
  5. int main(){
  6. int choice=0, i, total=0, j=0;
  7. double avg=0;
  8.  
  9. cout << "Enter a number between 1 and 1776: ";
  10. cin >> choice;
  11.  
  12. while(choice <1 || choice > 1776){
  13. cout << "Please enter a valid value, between 1 and 1776: ";
  14. cin >> choice;
  15. }
  16.  
  17. for(i=1776; i >= choice; i--){
  18. total += i;
  19. cout << setw(8) << i;
  20. j++;
  21. }
  22. avg = total /double(j);
  23. cout <<endl <<endl;
  24. cout << "Numbers output: " << j << endl <<"Total of numbers output: " <<total <<endl;
  25. cout << "Average of numbers output: " <<avg <<endl;
  26.  
  27.  
  28.  
  29. return 0;
  30. }
  31.  
  32. //Select a number, between 1 and 1776
  33. // Count down from 1776, to our number.
  34. //Print out the total, average;
  35.  
  36. //1772
  37. //1776,1775,1774,1773, 1772
  38.  
Success #stdin #stdout 0s 2728KB
stdin
1500
stdout
Enter a number between 1 and 1776:     1776    1775    1774    1773    1772    1771    1770    1769    1768    1767    1766    1765    1764    1763    1762    1761    1760    1759    1758    1757    1756    1755    1754    1753    1752    1751    1750    1749    1748    1747    1746    1745    1744    1743    1742    1741    1740    1739    1738    1737    1736    1735    1734    1733    1732    1731    1730    1729    1728    1727    1726    1725    1724    1723    1722    1721    1720    1719    1718    1717    1716    1715    1714    1713    1712    1711    1710    1709    1708    1707    1706    1705    1704    1703    1702    1701    1700    1699    1698    1697    1696    1695    1694    1693    1692    1691    1690    1689    1688    1687    1686    1685    1684    1683    1682    1681    1680    1679    1678    1677    1676    1675    1674    1673    1672    1671    1670    1669    1668    1667    1666    1665    1664    1663    1662    1661    1660    1659    1658    1657    1656    1655    1654    1653    1652    1651    1650    1649    1648    1647    1646    1645    1644    1643    1642    1641    1640    1639    1638    1637    1636    1635    1634    1633    1632    1631    1630    1629    1628    1627    1626    1625    1624    1623    1622    1621    1620    1619    1618    1617    1616    1615    1614    1613    1612    1611    1610    1609    1608    1607    1606    1605    1604    1603    1602    1601    1600    1599    1598    1597    1596    1595    1594    1593    1592    1591    1590    1589    1588    1587    1586    1585    1584    1583    1582    1581    1580    1579    1578    1577    1576    1575    1574    1573    1572    1571    1570    1569    1568    1567    1566    1565    1564    1563    1562    1561    1560    1559    1558    1557    1556    1555    1554    1553    1552    1551    1550    1549    1548    1547    1546    1545    1544    1543    1542    1541    1540    1539    1538    1537    1536    1535    1534    1533    1532    1531    1530    1529    1528    1527    1526    1525    1524    1523    1522    1521    1520    1519    1518    1517    1516    1515    1514    1513    1512    1511    1510    1509    1508    1507    1506    1505    1504    1503    1502    1501    1500

Numbers output: 277
Total of numbers output: 453726
Average of numbers output: 1638