I'm trying to take the number the user entered and keep adding it to the total then display the final total
extern void main()
{
//Ask user how many numbers they have to input
int iNum = 0;
cout%26lt;%26lt;';Enter how many numbers you have to enter: (or -1 to quit)';%26lt;%26lt; endl;
cin%26gt;%26gt; iNum;
int iTotal;
for ( int x = 1; x %26lt;= iNum; x++ )
{
cout %26lt;%26lt; ';Enter Number: ';%26lt;%26lt;endl;
cin %26gt;%26gt; iTotal;
int iGrandTotal;
iGrandTotal += iTotal;
}
cout %26lt;%26lt; ';Total is: '; %26lt;%26lt; iTotal %26lt;%26lt; endl;Unsure how I'm coding wrong...?
extern void main()
{
int iNum = 0;
int iInputNum;
int iGrandTotal;
//Ask user how many numbers they have to input
cout%26lt;%26lt;';Enter how many numbers you have to enter: (or -1 to quit)';%26lt;%26lt; endl;
cin%26gt;%26gt; iNum;
for ( int x = 1; x %26lt;= iNum; x++ )
{
cout %26lt;%26lt; ';Enter Number: ';%26lt;%26lt;endl;
cin %26gt;%26gt; iInputNum;
iGrandTotal += iInputNum;
}
cout %26lt;%26lt; ';Total is: '; %26lt;%26lt; iGrandTotal %26lt;%26lt; endl;
}Unsure how I'm coding wrong...?
us this your vars are all mixed up:
extern void main()
{
//Ask user how many numbers they have to input
int iNum = 0;
cout%26lt;%26lt;';Enter how many numbers you have to enter: (or -1 to quit)';%26lt;%26lt; endl;
cin%26gt;%26gt; iNum;
int iTotal;
int iGrandTotal;
for ( int x = 1; x %26lt;= iNum; x++ )
{
cout %26lt;%26lt; ';Enter Number: ';%26lt;%26lt;endl;
cin %26gt;%26gt; iTotal;
iGrandTotal += iTotal;
}
cout %26lt;%26lt; ';Total is: '; %26lt;%26lt; iGrandTotal %26lt;%26lt; endl;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment