Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

benlangdon

macrumors 65816
Original poster
Jan 13, 2008
1,497
0
this is what i got
how do i go from here to compile because it isn't letting me


/*
* HomeWork 8.h
*
*
* Created by Ben Langdon on 3/6/08.
* Copyright 2008 __MyCompanyName__. All rights reserved.
*
*/
#include <iostream>

using namespace std;

int main ( void )
{
int firstAge; //first age
int secAge; //second age
int ageSum; //sum of te ages
float avgAge; //average of ages

cout<<"\n\n\nBen Langdon\nLab1\n2-28-08\n\n";

//obtain2 ages from the user
cout<<"Enter first age:";
cin>>firstAge;
cout<<"Enter second age:";
cin>>secAge;

//Calculate the sum and average of the ages
ageSum = firstAge + secAge;
aveAge = ageSum / 2.0;

//Output tghe calculated results
cout<<"\nThe sum of the ages is "<<ageSum<<" and the average is "<<avgAge;
}
 

ebel3003

macrumors 6502a
Jun 20, 2007
630
0
"The Google"
The problem was that you declared a float as "avgAge" but then referred to it as "aveAge" later in the program. I've doctored it for you.

Code:
/*
* HomeWork 8.h
*
*
* Created by Ben Langdon on 3/6/08.
* Copyright 2008 __MyCompanyName__. All rights reserved.
*
*/
#include <iostream>

using namespace std;

int main ()
{
	int firstAge; //first age
	int secAge; //second age
	int ageSum; //sum of te ages
	float avgAge; //average of ages

	cout << "\n\n\nBen Langdon\nLab1\n2-28-08\n\n";

//obtain2 ages from the user
	cout << "Enter first age:";
	cin >> firstAge;
	cout << "Enter second age:";
	cin >> secAge;

//Calculate the sum and average of the ages
	ageSum = firstAge + secAge;
	avgAge = ageSum / 2.0;

//Output tghe calculated results
	cout << "\nThe sum of the ages is " << ageSum << " and the average is "<< avgAge;
}

In the future, it would be easier for you to post the code and the error that you're getting. It was easy enough to copy and paste in Xcode and hit compile, this time.
 

benlangdon

macrumors 65816
Original poster
Jan 13, 2008
1,497
0
ya i found that out.
i was writting it in c++ applications and now im doing it in c++ direct line something.
i tried posting the errors but it was over a page long.

but now my problem is when i compile and execute the program which works btw :), when i enter in a value it is supposed to go to the next value to be entered and it will not go to there for some reason. it happens and then it doesn't.


Code:
/*
#include <iostream>

using namespace std;

int main ( void )
{
	int itemPrice;     // Item price
	int tax;           // Tax
	float totalTax;    // Total tax
	float total;       // Entire price 
	
	cout<<"\n\n\nBen Langdon\nComputer Science 1a\nHW8\n3/06/08\n\n\n";
	
	//Enter item price
	cout<<"Enter Item:";
	cin>>itemPrice;
	cout<<"Enter Tax Amount:";
	cin>>tax;
	
	//Calculate
	totalTax = itemPrice * tax;
	total = totalTax + itemPrice;
	
	
	//Output the calculated results
	cout<<"\nThe amount of tax on the item is: "<<totalTax<<"\nTotal "<<total;
}
 

ebel3003

macrumors 6502a
Jun 20, 2007
630
0
"The Google"
Use the enter key next to the quote key rather than the number pad's enter key. I noticed this a little while when trying to compile your code.
 

benlangdon

macrumors 65816
Original poster
Jan 13, 2008
1,497
0
Use the enter key next to the quote key rather than the number pad's enter key. I noticed this a little while when trying to compile your code.

omg wtf is that.
thank you though
truly you have saved me so much time i already wrote the other 2 apps due tomorrow but it wouldn't execute it and i just tried and worked on all 3.

thank you so much.
i really appreciate the time you spent working with my code

thank you
 

benlangdon

macrumors 65816
Original poster
Jan 13, 2008
1,497
0
one last question :D
how do i let it be able to enter in a decimal for a value
like where do i place %
in the variable name or when its doing the action
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.