c++ - How can I separate this into 2 functions -


i wondering if me more elegant way code program writing please. code have bellow, know if there way separate part prints out totals new function. have tried total 0, must passing things wrong or something.

void printnumbers(int x, double y, double z, double v, int sum, double sum2,int sum3,int sum4){ while(x != 0){     y = sqrt (x);     z = pow (x,2);     v = pow (x,3);     sum = sum + x;     sum2 = sum2 + y;     sum3 = sum3 + z;     sum4 = sum4 + v;     cout << "       " << x << setw(12)  << setprecision (4) << y << setw(8) << z <<   setw(8) << v << endl;     x--; } cout << "       total is" << sum << setw(12) << sum2 << setw(8)<< sum3 << setw(8) << sum4 <<    endl; } 

this tried, @ time had 1 total get, still did not work gave answer 0:

void printfooters(int sum){  cout << " " << "====================================="<< endl;    cout << "totals " << sum << endl << endl; cout << " " << "====================================="<< endl; } 

this how calling in main():

printfooters(sum); 

you need make sums references if want them updated.

void printnumbers(int x, double y, double z, double v, int& sum, double& sum2,int& sum3,int&  sum4) 

if don't sums passed value, copy of current value of sums.

alternatively can use pointers sums, involve changing syntax when accessing sum variables.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -