I cant quite seem to get this totalsum function to work.
what I want it to do is if the user enters 4, it changes total to 10 (1+2+3+4=10). after trying several numbers I've determined it's adding all number except the final number (i.e user enter 4, it changes total to 6 1+2+3=6). please help me?
#include <iostream>
usingnamespace std;
void TotalSum(int Number1, int &Total);
int OddOrEven(int N1);
void main()
{
int Number, EvenOdd, Total=0;
do
{
cout<<"Please enter a number 1-100: ";
cin>>Number;
if (Number<=100)
TotalSum(Number, Total);
elsebreak;
EvenOdd=OddOrEven(Number);
if (EvenOdd==1)
cout<<"This number is even."<<endl;
else
cout<<"This number is odd."<<endl;
cout<<"The total of all between 1 and "<<Number<<" are: "<<Total<<endl;
Total=0;
}
while (Number<=100);
}
void TotalSum(int Number1, int &Tot)
{
int Begin;
for (Begin=1;Begin<Number1;Begin++)
Tot=Tot+Begin;
}
int OddOrEven(int N1)
{
if (N1%2==0)
return 1;
elsereturn 2;
}