|
| |||||||||||||||||||||||||||||||||||||
| naushil (4) | |
|
please explain im totally beginner,how can i compile?Basically the requirement is that output should show three lines 1st line int division 2nd double division 3rd min and max number and division thanks. here is my code, #include <iostream> using std::cout; using std::endl; using std::cin; #include<cstdarg> //function prototype(s) int avg(int,...); int main() { // identifying output statements cout << "Programmer: Naushil Mehta" << endl; cout << "Description: This program gives you the average of floating point numbers." << endl; cout<<"The average of 6 test scores is "<<avg(6,50,81,92,73,84,95)<<endl; return 0; } //return average of a variable length list of integers int avg(int n, ...)//"n" is the number of numbers in the list;"..."is the list { va_list list; // assign the name "list" to the variable length list of integers va_start(list,n);//tell c++ that the list begins after the argument "n" int num;//store the numbers from the list in "num" as they are "read" //create the total of "n" numbers in the list int total=0;//track the total of the numbers in the list for(int i=0;i<n;i++) { num=va_arg(list,int);//set num equal to the next number in the list,as an int total=total+num;//increment the total } va_end(list);//close the list--REQUIRED // compute and return the average return total/n; } //===================// { cout<<"The average of 7 test scores is "<<avg(7.0,59.86,50.23,81.55,55.92,67.23,84.43,95.43)<<endl; } double davg(double m, ...)//"m" is the number of numbers in the list;"..."is the list { va_list list; // assign the name "list" to the variable length list of integers va_start(list,m);//tell c++ that the list begins after the argument "m" double num;//store the numbers from the list in "num" as they are "read" //create the total of "m" numbers in the list double total=0;//track the total of the numbers in the list for(double i=0;i<m;i++) { num=va_arg(list,double);//set num equal to the next number in the list,as a double total=total+num;//increment the total } va_end(list);//close the list--REQUIRED // compute and return the average return total/m; } //=======================// int avgx (int,...) { int a, aMax, aMin; a = avgx(aMax, aMin, 8, 23,55,45,67,42,44,70,98); cout<<"The average of 8 scores is "<<avgx<<endl; return 0; }// //returns average and passes max and min back through argument list int avgx(int& mx,int& mn,int n,...)//n is the number of numbers in the list { va_list list;//assign the name "list" to the variable length list of integers va_start(list,n);//tell c++ that the list begins after the argument "n" int num;//store the numbers from the list in "num" as they are "read" //create the total of "n" numbers in the list int total=0;//track the total of the numbers in the list for (int i=0;i<n; i++) { num=va_arg(list,int);//set num equal to the next number in the list,as an int if((i==0) ||(mn>num))//update min value mn=num; if((i=0)||(mx<num))//update max value mx= num; total=total+num;//increment the toal } va_end(list);//close the list--required //compute and return the average return total/n; } | |
|
|
|
| firedraco (5671) | |
|
Please use code tags so I can figure out where line 42 is: http://cplusplus.com/articles/z13hAqkS/ | |
|
|
|
| naushil (4) | |
| how do i do that?is it automated or i have to put manually.i visited the link u posted. | |
|
|
|
| Disch (9302) | |
|
[code]put your code here[/code] If you visited the link he posted you would have noticed that it told you how to do it in the 2nd sentence. | |
|
Last edited on
|
|