Re: C++ School Final Project
1. Post code inside [code][/code] to preserve formating on the forum.
Quote:
void cat01(int 1,2,3,4,5,6,7,8,9,addition,average,y,numgrade
2. Variable names can not start with a number, 1 always means the number 1, not a variable.
3. If a function has more then one parameter you need to redeclare the type for each one:
Code:
void cat(int v1, int v2, int v3, int v4) { ... }
4. main should have return type int, not void. Add return 0 at the end.
5. Why does the cat01 function have 9 parameters, and why have you duplicated the function? Do you know how to use arrays? They will make your code a lot easier. Also, you shouldn't declare all variables you need as arguments (between the parentheses), use local variables instead:
Code:
void cat01() {
int numgrade;
double avarage;
// etc.
}
6. Instead of returning stuff in global variables you should make the functions return the value:
Code:
double cat(something) {
...
return sum / number;
}
...
int main() {
...
double avarage1 = cat(...);
...
double avarage2 = cat(...);
}
This way you can reuse the function.
7. your avarage calculation will always yield a whole number, if you add integers the result will be an integer, if you divide two integers the result is an integer as well. That integer will be cast to a double, giving a whole number. You should instead cast one of the numbers to a double:
Code:
double avarage = (double)sum / number;
Re: C++ School Final Project
First, sorry for not using the [code] tags... I did not know. Secondly,I do not currently know how to use arrays. My computer teacher unfortunately is not very good. I will work in your suggestions into my programming. Thanks for the help!
Re: C++ School Final Project
Indeed ...
You should not #include .cpp files. #include apstring.h and compile apstring.cpp separately, then link it with your program. (In other words, add it to the project.)
Re: C++ School Final Project
I took some of the advice except for using arrays since I do not know how to use them and the project is due in a very short period of time.
Code:
/* Daniel Gonzalez
Start Date: 01/03/06
Due Date: 1/11/06
This program calculates a person's average in a class
It works by asking the person to input the name of x number categories and how much each is worth**.
It then asks the person to input how many grades are to be inputed under each category** */
//--------------------------------------------------------------------------------------
#include <iostream.h >
#include <math.h>
#include <apstring.cpp>
//--------------------------------------------------------------------
int cat01(double a1, double a2,double a3,double a4,double a5,double a6, double a7,double a8,double a9, double addition, double average, double y, double numgrade)
/* Gets the average of up to 9 numbers worth x% of the grade */
{
cout << "Enter the amount of grades ";
cin >> numgrade;
y=0;
while (numgrade >0 )
{
cin >> a1;
y++;
numgrade--;
cin >> a2;
y++;
numgrade--;
cin >> a3;
y++;
numgrade--;
cin >> a4;
y++;
numgrade--;
cin >> a5;
y++;
numgrade--;
cin >> a6;
y++;
numgrade--;
cin >> a7;
y++;
numgrade--;
cin >> a8;
y++;
numgrade--;
cin >> a9;
y++;
numgrade--;
}
addition= 1+2+3+4+5+6+7+8+9;
average= (double)addition/y;
return average;
}
//--------------------------------------------------------------------------------------
//-------------------------------------
int main()
{
apstring cat1;
apstring cat2;
apstring cat3;
apstring cat4;
apstring cat5;
apstring cat6;
apstring cat7;
apstring cat8;
apstring cat9;
double numcat;
double numper;
double funcnum;
double percent1;
double percent2;
double percent3;
double percent4;
double percent5;
double percent6;
double percent7;
double percent8;
double percent9;
double average1;
double average2;
double average3;
double average4;
double average5;
double average6;
double average7;
double average8;
double average9;
char yn;
do {
cout << "Enter the amount of categories :";
cin >> numcat;
cout << "Enter the names of the categories : "<< endl;
while ( numcat >0 )
{
cin >> cat1;
numcat--;
cin >> cat2;
numcat--;
cin >> cat3;
numcat--;
cin >> cat4;
numcat--;
cin >> cat5;
numcat--;
cin >> cat6;
numcat--;
cin >> cat7;
numcat--;
cin >> cat8;
numcat--;
cin >> cat9;
numcat--;
}
cout << "Please re-enter the amount of categories ";
cin >> numper;
cout << "Enter how much of the percent is each category worth (in decimal form) : ";
while (numper > 0)
{
cin >> percent1;
numper--;
cin >> percent2;
numper--;
cin >> percent3;
numper--;
cin >> percent4;
numper--;
cin >> percent5;
numper--;
cin >> percent6;
numper--;
cin >> percent7;
numper--;
cin >> percent8;
numper--;
cin >> percent9;
numper--;
}
cout << "Please re-enter the amount of categories: ";
cin >> funcnum;
while (funcnum > 0) {
average1 = cat01();
funcnum--;
}
cout << "If you would like to continue type Y. If you would like to stop press N . ";
cin >> yn;
} while (yn == 'Y' || yn == 'y');
if (yn == 'N' || yn == 'n')
cout << "Thank you for using Daniel Gonzalez's Grade Calculator!" << endl;
cout << "Have a nice day!" << endl;
return(0);
}
My error is that it says that cat01 has no parameters. What should i do to fix this error?
Sorry for being such a bother
Woomba
Re: C++ School Final Project
Code:
average1 = cat01();
You're calling the function without the 1052352 parameters you declared.
By the way, your input stuff won't work the way you intend it to. It looks like you wrote the code so that you can use arrays, but then didn't, and in a very weird way, too. And making the user enter the amount of categories three (correction: three + the third value he enters) times is ridiculous - just copy the value! (You know how to assign one variable to the other, do you?)
There are various other problems with the code, but I doubt you still have time to fix them.
Edit: Looking at it more closely, this code is so horribly broken, it's not even funny. What happens to all the parameters you pass to cat01? What's that name supposed to mean, anyway?
Where to begin ...?
Re: C++ School Final Project
At least he's learning....
Isnt that all we ask for...
Then again as he stated... His teacher is a dumbass(My way of saying that he doesnt know everything.even the stuff he teaches).
Re: C++ School Final Project
Using my very rendundant method of programming, I have almost fully completed my program.If you look at my program now you could see how I have incorporated suggestsions from this forum and other into the program Currently i get no errors while compiling, but my averages are giving me weird numbers such as 1.0990e+9. If you could help me with the last aspect of my code I would be eternaly greatful
Code:
//--------------------------------------------------------------------------------------
#include <iostream.h >
#include <math.h>
#include <apstring.cpp>
//--------------------------------------------------------------------
double cat01()
/* Gets the average of up to 9 numbers worth x% of the grade */
{
double a1;
double a2;
double a3;
double a4;
double a5;
double a6;
double a7;
double a8;
double a9;
double addition;
double average;
double y;
double numgrade;
cout << "Enter the amount of grades ";
cin >> numgrade;
y=0;
if (numgrade >0)
cin >> a1;
numgrade--;
y++;
if (numgrade >0)
cin >> a2;
y++;
numgrade--;
if (numgrade >0)
cin >> a3;
y++;
numgrade--;
if (numgrade >0)
cin >> a4;
y++;
numgrade--;
if (numgrade >0)
cin >> a5;
y++;
numgrade--;
if (numgrade >0)
cin >> a6;
y++;
numgrade--;
if (numgrade >0)
cin >> a7;
y++;
numgrade--;
if (numgrade >0)
cin >> a8;
y++;
numgrade--;
if (numgrade >0)
cin >> a9;
y++;
numgrade--;
addition= a1+a2+a3+a4+a5+a6+a7+a8+a9;
average= (double)addition/y;
return average;
}
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
int main()
{
apstring cat1;
apstring cat2;
apstring cat3;
apstring cat4;
apstring cat5;
apstring cat6;
apstring cat7;
apstring cat8;
apstring cat9;
double numcat;
double numcat3;
double numcat4;
double numcat5;
double percent1;
double percent2;
double percent3;
double percent4;
double percent5;
double percent6;
double percent7;
double percent8;
double percent9;
double average1=0;
double average2=0;
double average3=0;
double average4=0;
double average5=0;
double average6=0;
double average7=0;
double average8=0;
double average9=0;
double final1;
double final2;
double final3;
double final4;
double final5;
double final6;
double final7;
double final8;
double final9;
double ultfinaladd;
double ultfinal;
char yn;
do {
cout << "Enter the amount of categories :";
cin >> numcat;
cout << "Enter the names of the categories : "<< endl;
if (numcat >0)
cin >> cat1;
numcat--;
if (numcat >0)
cin >> cat2;
numcat--;
if (numcat >0)
cin >> cat3;
numcat--;
if (numcat >0)
cin >> cat4;
numcat--;
if (numcat >0)
cin >> cat5;
numcat--;
if (numcat >0)
cin >> cat6;
numcat--;
if (numcat >0)
cin >> cat7;
numcat--;
if (numcat >0)
cin >> cat8;
numcat--;
if (numcat >0)
cin >> cat9;
numcat--;
cout << "Please re-enter the amount of categories"<< endl;
cin >> numcat3;
cout << "Enter how much of the percent is each category worth (in decimal form) : ";
if (numcat3 > 0)
cin >> percent1;
numcat3--;
if (numcat3 >= 0)
cin >> percent2;
numcat3--;
if (numcat3 > 0)
cin >> percent3;
numcat3--;
if (numcat3 > 0)
cin >> percent4;
numcat3--;
if (numcat3 > 0)
cin >> percent5;
numcat3--;
if (numcat3 > 0)
cin >> percent6;
numcat3--;
if (numcat3 > 0)
cin >> percent7;
numcat3--;
if (numcat3 > 0)
cin >> percent8;
numcat3--;
if (numcat3 > 0)
cin >> percent9;
numcat3--;
cout << "Please re-enter the amount of categories"<< endl;
cin >> numcat4;
if (numcat4 > 0)
average1 = cat01();
numcat4--;
if (numcat4 > 0)
average2 = cat01();
numcat4--;
if (numcat4 > 0)
average3 = cat01();
numcat4--;
if (numcat4 > 0)
average4 = cat01();
numcat4--;
if (numcat4 > 0)
average5 = cat01();
numcat4--;
if (numcat > 0)
average6 = cat01();
numcat4--;
if (numcat4 > 0)
average7 = cat01();
numcat4--;
if (numcat4 > 0)
average8 = cat01();
numcat4--;
if (numcat4 > 0)
average9 = cat01();
numcat4--;
cout << "Please re-enter the amount of categories"<< endl;
cin >> numcat5;
if (numcat5 > 0)
cout << "The average of " << cat1 << " is" << average1 << endl;
numcat5--;
if (numcat5 > 0)
cout << "The average of " << cat2 << " is" << average2 << endl;
numcat5--;
if (numcat5 > 0)
cout << "The average of " << cat3 << " is" << average3 << endl;
numcat5--;
if (numcat5 > 0)
cout << "The average of " << cat4 << " is" << average4 << endl;
numcat5--;
if (numcat5 > 0)
cout << "The average of " << cat5 << " is" << average5 << endl;
numcat5--;
if (numcat5 > 0)
cout << "The average of " << cat6 << " is" << average6 << endl;
numcat5--;
if (numcat5 > 0)
cout << "The average of " << cat7 << " is" << average7 << endl;
numcat5--;
if (numcat5 > 0)
cout << "The average of " << cat8 << " is" << average8 << endl;
numcat5--;
if (numcat5 > 0)
cout << "The average of " << cat9 << " is" << average9 << endl;
numcat5--;
double numcat9;
cout << "Enter the amount of categories again" << endl;
cin >> numcat9;
final1=average1*percent1;
final2=average2*percent2;
final3=average3*percent3;
final4=average4*percent4;
final5=average5*percent5;
final6=average6*percent6;
final7=average7*percent7;
final8=average8*percent8;
final9=average9*percent9;
ultfinaladd= average1+average2+average3+average4+average5+average6+average7+average8+average9;
ultfinal= (double)ultfinaladd/numcat9;
cout << "Your final grade is " << ultfinal << "percent" << endl;
if (ultfinal < 60)
cout << "You failed!" << endl;
else if (ultfinal < 70 && ultfinal >= 60)
cout << "You barely passed with a D!" << endl;
else if (ultfinal < 80 && ultfinal >= 70)
cout << "You passed with a C!" << endl;
else if (ultfinal < 90 && ultfinal >= 80)
cout << "You did great with a B!" << endl;
else if (ultfinal < 100 && ultfinal >= 90)
cout << "You did great and got an A!" << endl;
else if (ultfinal >= 100)
cout << "Amazing! You got a perfect score!" << endl;
cout << "If you would like to continue type Y. If you would like to stop press N . ";
cin >> yn;
} while (yn == 'Y' || yn == 'y');
if (yn == 'N' || yn == 'n')
cout << "Thank you for using Daniel Gonzalez's Grade Calculator!" << endl;
cout << "Have a nice day!" << endl;
return(0);
}
P.S. instead of repeating this course in school, I plan on taking the class at a community-college in my area. Hopefully I will receive better instruction/ learn more
Re: C++ School Final Project
I finally got my project to work perfectly! (Up to nine numbers in each category)