I have this activity for programming class. I'm only allowed to place codes where it says "add code here". I managed to get some voids to work but i keep having compile error showing "too many arguments to function 'void MilesPerrGallon(double, double)'". Can anyone tell whats going on? Tnx :D
const int size=10;// use in menu[1] miles per gallon
typedef double pointers;
void MilesPerrGallon(double ptr1,double ptr2);//process and display milespergallon
void MperG();//input miles and gallons and call function MilePerGallon
void getSort();//use dynamic array and a sort techniques to sort n values
void displaySort(int ptr,int smax);//displaying the vsorted values in descending order
char displayMenu(char *pt);//display the option on screen and return values 1,2 or 3
//using a pointer variable
int main()
{
char ans,sagot;
char *ptr;
//add code here
do{
ptr=&sagot;
do
{
ans=displayMenu(ptr);
}while(ptr!='1'&&ptr!='2'&&*ptr!='3');
switch(sagot)
{
//add code here
case '1':
{
MperG();
}
break;
case '2':
{
}
break;
case '3':
{
cout<<"goodbye for now....\n";
system("pause");
exit(1);
}
exit(1);
break;
}
do
{
cout<<"Try Again?[y/n]:";
cin>>*ptr;
*ptr=tolower(*ptr);
}while(*ptr!='y'&&*ptr!='n');
}while(*ptr=='y');
cout<<endl;
cout<<"Thank you for using my program!";
system("pause>0");
return 0;
}
/////////////////////////
void MperG()
{double miles[size],gallons[size];
int ctr;
pointers milPtr,galPtr;
int msize;
system("cls");cout<<"COMPUTING FOR MPG : miles per gallon...\n";cout<<"MILES\n";//addcodeherewhile(true){cout<<"Size must be from 5 to 15 only.\n\n";cout<<"Specify the size of the array: ";cin>>msize;try{if(msize>15||msize<3)throwmsize;break;}catch(intx){cout<<"\nSIZE MUST BE FROM 5 TO 15 ONLY!";system("pause>0");system("cls");continue;}}milPtr=newdouble[msize];galPtr=newdouble[msize];cout<<"\n\n\nMiles\n";for(ctr=0;ctr<msize;ctr++){boolans=true;while(ans){cout<<"The number must be from 100-250 only.\n\n";cout<<"Miles ("<<ctr<<"): ";cin>>*(milPtr+ctr);try{if(*(milPtr+ctr)>250||*(milPtr+ctr)<100)throw*(milPtr+ctr);break;}catch(doublee){cout<<e<<" IS INVALID. THE NUMBER MUST BE FROM 100-250 ONLY!";system("pause>0");system("cls");continue;}}}
/*********/
cout<<"GALLONS\n";
//add code here
cout<<"The number must be from 5-25 only.\n\n";
for(ctr=0;ctr<msize;ctr++)
{
bool ans=true;
while(ans)
{
cout<<"Gallons ("<<ctr<<"): ";
cin>>*(galPtr+ctr);
try
{
if((*galPtr+ctr)>25||*(galPtr+ctr)<5)
throw *(galPtr+ctr);
break;
}
catch(double e)
{
cout<<e<<" IS INVALID. THE NUMBER MUST BE FROM 5-25 ONLY!";
system("pause>0");
system("cls");
continue;
}
}
}
//call MilePerrGallon here
MilesPerrGallon(milPtr,galPtr,msize);
I have this activity for programming class. I'm only allowed to place codes where it says "add code here". I managed to get some voids to work but i keep having compile error showing "too many arguments to function 'void MilesPerrGallon(double, double)'". Can anyone tell whats going on? Tnx :D
========================================================================
include<iostream></iostream>
include<iomanip></iomanip>
using namespace std;
const int size=10;// use in menu[1] miles per gallon
typedef double pointers;
void MilesPerrGallon(double ptr1,double ptr2);//process and display milespergallon
void MperG();//input miles and gallons and call function MilePerGallon
void getSort();//use dynamic array and a sort techniques to sort n values
void displaySort(int ptr,int smax);//displaying the vsorted values in descending order
char displayMenu(char *pt);//display the option on screen and return values 1,2 or 3
//using a pointer variable
int main()
{
char ans,sagot;
char *ptr;
//add code here
do{
ptr=&sagot;
do
{
ans=displayMenu(ptr);
}while(ptr!='1'&&ptr!='2'&&*ptr!='3');
}
/////////////////////////
void MperG()
{double miles[size],gallons[size];
int ctr;
pointers milPtr,galPtr;
int msize;
/*********/
cout<<"GALLONS\n";
//add code here
cout<<"The number must be from 5-25 only.\n\n";
//call MilePerrGallon here
MilesPerrGallon(milPtr,galPtr,msize);
}
////////////////////////
void MilesPerrGallon(double ptr1,double ptr2)
{
}
///////////////////////////////////////
void getSort()
{
//add code here
//call displaysort here
void displaySort(int *ptr,int smax);
}
/////////////////////////
void displaySort(int *ptr,int smax)
{
//add code here
}
////////////////////////////////////////////
//////////////////////////////////////////
char displayMenu(char pt)
{
//add code here
cout<<"MAIN MENU"<<endl
<<"[1] - MPG (Miles Per Gallon)"<<endl
<<"[2] - Sorting of Numbers"<<endl
<<"[3] - Exit Program"<<endl
<<"Enter Option: ";
cin>>pt;
return *pt;
}
Last edit: Robbert Williams 2016-05-15