• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

C++ Newb needs some help

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Circaflex

Member
Joined
Aug 6, 2003
Location
Irvine, CA
well im doing this project for class and im terrible so far at c++ and im switching majors either way, but im still taking the class. i have this project mostly done just a few errors which i dont know how to exactly fix. take a look if you have some time.

Assignment:
Given the following main() function, write the complete form of each function called in the main(). Test your program and show all outputs.

int main()
{
int x,y, z;
// read three numbers into x, y, and z
ReadData(x,y,z);

// compute and return the total of x, y, and z
int sum=ComputeTotal(x,y,z);

// find the maximum and the minimum of x,y, and z
int max, min;
FindMaxMin(x,y,z,max,min);
cout<<" for x= "<<x<<" y= "<<y<<" z= "<<z<<endl;
cout<<"\tMaximum= "<<max<<" and Minimum= "<<min<<endl;

// find and return the average of x,y, and z
float average=FindAverage(x,y,z);
cout<<fixed<<showpoint<<setprecision(2);
cout<<" the average of x= "<<x<<" y= "<<y<<" z= "<<z<<endl;
cout<<"\tis"<<average<<endl;

// draw bargraph. For example if x=3, y=6, z=4, the output should look
//like this
// x:***
// y:******
// z:****

now heres my code so far

Code:
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

//reads three numbers into x, y , and z
void ReadData ( int&a, int&b, int&c)
{
	cout<<"Enter three numbers:";
	cin>>a>>b>>c;
}

//compute and return the total of x, y, and z
void ComputeTotal( int a, int b, int c, int total)
{
	total=a + b + c;
}

//find the maximum and minimum of x, y, and z
void FindMaxMin(int a, int b, int c, int&mx, int&mn)
{
	if(a < b && a < c && b > c)
	{
		mn=a; mx=b;
	}
	if(a < b && a < c && b < c)
	{
		mn=a; mx=c;
	}
	if(a > b && a > c && b < c)
	{
		mn=b; mx=a;
	}
	else
	{
		mn=c; mx=a;
	}
}

//find and return the average of x, y, and z
void FindAverage(int a, int b, int c, float average)
{
	average = (a + b + c)/3.;
}

//draws the bargraphs depending on the numbers entered by the user
void DrawBargraph(int n, int p)
{
	for (int n=1; n<=a; ++n)
	{ cout<<"*";
	}
	cout<<endl;
}

int main()
{
	int x,y, z;
// read three numbers into x, y, and z
	ReadData(x,y,z);

// compute and return the total of x, y, and z
	int sum=ComputeTotal(x,y,z);

// find the maximum and the minimum of x,y, and z
	int max, min;
	FindMaxMin(x,y,z,max,min);
	cout<<" for x= "<<x<<" y= "<<y<<" z= "<<z<<endl;
	cout<<"\tMaximum= "<<max<<" and Minimum= "<<min<<endl;

// find and return the average of x,y, and z
	float average=FindAverage(x,y,z);
	cout<<fixed<<showpoint<<setprecision(2);
	cout<<" the average of x= "<<x<<" y= "<<y<<" z= "<<z<<endl;
	cout<<"\tis"<<average<<endl;

// draw bargraph
	DrawBargraph(x,y,z);
	
//terminate program
	return 0;
}
 
Circaflex said:
well im doing this project for class and im terrible so far at c++ and im switching majors either way, but im still taking the class. i have this project mostly done just a few errors which i dont know how to exactly fix. take a look if you have some time.

Assignment:


now heres my code so far

Code:
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

//reads three numbers into x, y , and z
void ReadData ( int&a, int&b, int&c)
{
	cout<<"Enter three numbers:";
	cin>>a>>b>>c;
}

//compute and return the total of x, y, and z
void ComputeTotal( int a, int b, int c, int total)
{
	total=a + b + c;
}

//find the maximum and minimum of x, y, and z
void FindMaxMin(int a, int b, int c, int&mx, int&mn)
{
	if(a < b && a < c && b > c)
	{
		mn=a; mx=b;
	}
	if(a < b && a < c && b < c)
	{
		mn=a; mx=c;
	}
	if(a > b && a > c && b < c)
	{
		mn=b; mx=a;
	}
	else
	{
		mn=c; mx=a;
	}
}

//find and return the average of x, y, and z
void FindAverage(int a, int b, int c, float average)
{
	average = (a + b + c)/3.;
}

//draws the bargraphs depending on the numbers entered by the user
void DrawBargraph(int n, int p)
{
	for (int n=1; n<=a; ++n)
	{ cout<<"*";
	}
	cout<<endl;
}

int main()
{
	int x,y, z;
// read three numbers into x, y, and z
	ReadData(x,y,z);

// compute and return the total of x, y, and z
	int sum=ComputeTotal(x,y,z);

// find the maximum and the minimum of x,y, and z
	int max, min;
	FindMaxMin(x,y,z,max,min);
	cout<<" for x= "<<x<<" y= "<<y<<" z= "<<z<<endl;
	cout<<"\tMaximum= "<<max<<" and Minimum= "<<min<<endl;

// find and return the average of x,y, and z
	float average=FindAverage(x,y,z);
	cout<<fixed<<showpoint<<setprecision(2);
	cout<<" the average of x= "<<x<<" y= "<<y<<" z= "<<z<<endl;
	cout<<"\tis"<<average<<endl;

// draw bargraph
	DrawBargraph(x,y,z);
	
//terminate program
	return 0;
}

The ComputeTotal and FindAverage functions have too many arguments and need to return somerthing. Try these:
Code:
int ComputeTotal( int a, int b, int c)
{
	return a + b + c;
}
float FindAverage(int a, int b, int c)
{
	return (a + b + c)/3.0;
}
 
Back