small++ large-1
Write your question here.
Hi, I am having trouble with the count calculators for this code - small++; large-1; Can someone see what i have done wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
int main()
{
using namespace std;
unsigned short small;
unsigned long large;
const unsigned short MAXSMALL=65535;
cout << "Enter a small number: ";
cin >> small;
cout << "Enter a large number: ";
cin >> large;
cout << "small:" << small << "...";
//for each iteration, test two conditions
while (small < large && small < MAXSMALL)
{
if (small % 5000 == 0) //write a dot every 5k lines
cout << ".";
small++;
large-1;<#statements#>
}
cout << "\nSmall: " << small << " Large: " << large << endl;
return 0;
}
|
Just like small++;
it's large--;
large-1;
doesn't actually do anything. Well, it calculates a result, but doesn't store it or use it in any way.
Did you mean to put
large--;
or the equivalent
large = large-1;
?
By the way, instead of
|
const unsigned short MAXSMALL=65535;
|
it is safer to write
|
const unsigned short MAXSMALL = std::numeric_limits<unsigned short>::max();
|
and let the system supply the appropriate value.
remember to add
#include <limits>
http://www.cplusplus.com/reference/limits/numeric_limits/
Topic archived. No new replies allowed.