October 21st, 2013, 04:01 PM
Allowing user to input decimal.
This code is near complete, the only task that is left is allowing the user to input a decimal and then two integers, or automatically using .00 decimal.
The automatic part: /*This is not correct.
But that does no good for me. Question: Do I have to create a some sort of while loop again, to allow the user to input a decimal followed by integer?
using namespace std;
int j , i = 0, k = 0;
double sum = 0.0;
double Average = 0.0;
cout << "Enter Positive integer number: ";
while(cin >> number)
cout << endl;
if( number < 0)//test if the number is negative
cout << "Ending program since user has input a negative number" <<endl;
int temp = number;
int p = 1;
sum = (sum+temp);
Average = sum/2;
while(temp > 0) //counting number of digits
temp /= 10;
p *= 10;
cout << "Total Sum: " << sum << endl;
cout << "Average: "<< Average << endl;
j = i % 3;
p /= 10;
while( i > 0 )//display integer number with 1000 seperator
//entering gives me error if digits exceed 9
cout << char ((number/p) +'0');
number %= p;
p /= 10;
if ((k % 3 == 0 && i > 0)||(j == 0 && i > 2) )
k = 0;
/*This is not correct.
cout << endl << endl;
cout << "This program exits if you input negative number and/or input non-integer\n";
cout << "Enter another integer number: ";
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!