3 Grade Average

Average Calculator with 5 Functions

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 914 Views - Last Post: 19 October 2009 - 09:54 PM Rate Topic: -----

#1 Photographer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-October 09

3 Grade Average

Post icon  Posted 19 October 2009 - 07:41 PM

Hello! Everyone I Have This Code I'm Working on but I'm Getting a few Errors if some one could shed some light
Basically i took "seeP+" 's code from this Thread DreamInCode and tried to make it with "5 functions" = 1 main; 3xInputs & 1 Average Calculator" heres the Code I APOLOGIZE FOR THE SPANISH I JUST TRANSLATED THE OP'S COMMENTS TO SPANISH PLEASE NO FLAMING

// funciones promedio

#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <conio.h>
#include <iostream>

using namespace std;


//funciones
double promedio (int, int, int);
int nota1 (int);
int nota2 (int);
int nota3 (int);


//cin de notas
int Nota1(int nota1)

{ 
 nota1=0;
 cout << "\nEntre Primera Nota: \a";
 cin >> nota1;
 return nota1;
}

int Nota2(int nota2)
{ 
 nota2=0;
 cout << "\nEntre Primera Nota: \a";
 cin >> nota2;
 return nota2;
}

int Nota3(int nota3)
{ 
 nota3=0;
 cout << "\nEntre Primera Nota: \a";
 cin >> nota3;
 return nota3;

}





//funcion promedio
double promedio (int num1, int num2, int num3)
{
double average = 0.0;
average = double(num1 + num2 + num3) / 3.0;


return average;


} //end de la funcion promedio 



int main()
{

	

//llamado a funcion para calcular promedio
average //= promedio (nota1, nota2, nota3);
cout << "\nEl Promedio de las 3 Notas es: \a" << average << endl;
cout << "\nPresione Cualquier tecla Para Salir...";


getch();

return 0;
} //end de la funcion main




Here is the "output":

1>------ Build started: Project: 06, Configuration: Debug Win32 ------
1>Compiling...
1>06.cpp
1>c:\users\*****\desktop\vs projects\06\06\06.cpp(72) : error C2065: 'average' : undeclared identifier
1>c:\users\*****\desktop\vs projects\06\06\06.cpp(72) : error C2146: syntax error : missing ';' before identifier 'cout'
1>c:\users\*****\desktop\vs projects\06\06\06.cpp(72) : error C2065: 'average' : undeclared identifier
1>Build log was saved at "file://c:\Users\*****\Desktop\VS Projects\06\06\Debug\BuildLog.htm"
1>06 - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This post has been edited by Photographer: 19 October 2009 - 07:47 PM


Is This A Good Question/Topic? 0
  • +

Replies To: 3 Grade Average

#2 jwwicks  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 162
  • Joined: 31-July 08

Re: 3 Grade Average

Posted 19 October 2009 - 07:50 PM

Hello,

View PostPhotographer, on 19 Oct, 2009 - 06:41 PM, said:

// funciones promedio

int main()
{

//llamado a funcion para calcular promedio
average //= promedio (nota1, nota2, nota3);
cout << "\nEl Promedio de las 3 Notas es: \a" << average << endl;
cout << "\nPresione Cualquier tecla Para Salir...";
getch();
return 0;
} //end de la funcion main



Just add this to main:

double average = 0.0;



Jw
Was This Post Helpful? 0
  • +
  • -

#3 Tshiknn  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 20
  • Joined: 18-October 09

Re: 3 Grade Average

Posted 19 October 2009 - 07:51 PM

If you could tell me what "Notal" means, I could probably help you. :)
Was This Post Helpful? 0
  • +
  • -

#4 Photographer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-October 09

Re: 3 Grade Average

Posted 19 October 2009 - 07:56 PM

View PostTshiknn, on 19 Oct, 2009 - 06:51 PM, said:

If you could tell me what "Notal" means, I could probably help you. :)



Nota1 = Grade1

Promedio = Average


View Postjwwicks, on 19 Oct, 2009 - 06:50 PM, said:

Hello,

View PostPhotographer, on 19 Oct, 2009 - 06:41 PM, said:

// funciones promedio

int main()
{

//llamado a funcion para calcular promedio
average //= promedio (nota1, nota2, nota3);
cout << "\nEl Promedio de las 3 Notas es: \a" << average << endl;
cout << "\nPresione Cualquier tecla Para Salir...";
getch();
return 0;
} //end de la funcion main



Just add this to main:

double average = 0.0;



Jw



I Did And Only said This

1>c:\users\*****\desktop\vs projects\06\06\06.cpp(71) : error C2664: 'promedio' : cannot convert parameter 1 from 'int (__cdecl *)(int)' to 'int'

Almost There!

This post has been edited by Photographer: 19 October 2009 - 07:53 PM

Was This Post Helpful? 0
  • +
  • -

#5 brds  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 76
  • View blog
  • Posts: 515
  • Joined: 22-October 08

Re: 3 Grade Average

Posted 19 October 2009 - 07:58 PM

Hows about you change average //= promedio(nota1, nota2, nota3); to average /= promedio(nota1(1), nota2(2), nota3(3));.

// starts a comment. nota# is a function that requires that you pass an int.

Of course you realize that average /= promedio(nota1(1), nota2(2), nota3(3)); is functionally the same as average /= promedio(1, 2, 3);?

Also, cut & pasting code you don't understand is not wise.
Was This Post Helpful? 0
  • +
  • -

#6 Photographer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-October 09

Re: 3 Grade Average

Posted 19 October 2009 - 08:05 PM

I DID UNDERSTAND THE CODE Man; i just not getting the mods i want to make to it; I know it's an disgrace to the Original Code; But at least i'm trying....

This post has been edited by Photographer: 19 October 2009 - 08:06 PM

Was This Post Helpful? 0
  • +
  • -

#7 brds  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 76
  • View blog
  • Posts: 515
  • Joined: 22-October 08

Re: 3 Grade Average

Posted 19 October 2009 - 08:18 PM

Oh wait my bad... = not /=, you probably don't want to divide.

My OP wasn't meant to insult. Could you post current code & errors if any?
Was This Post Helpful? 0
  • +
  • -

#8 Photographer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-October 09

Re: 3 Grade Average

Posted 19 October 2009 - 08:27 PM

View Postbrds, on 19 Oct, 2009 - 07:18 PM, said:

Oh wait my bad... = not /=, you probably don't want to divide.

My OP wasn't meant to insult. Could you post current code & errors if any?



No Problem Dude Sorry For The CAPS lol :rolleyes:
Here's where i am @ the moment: no errors it runs but i only see the couts of the (int main) it only shows:

________________________________
|El Promedio de las 3 Notas es: 2 |
|Presione Cualquier tecla Para Salir... |
| |
|_______________________________|
// funciones promedio

#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <conio.h>
#include <iostream>

using namespace std;


//funciones
double promedio (int, int, int);
int nota1 (int);
int nota2 (int);
int nota3 (int);


//cin de notas
int Nota1(int nota1)

{ 
 nota1=0;
 cout << "\nEntre Primera Nota: \a";
 cin >> nota1;
 return nota1;
}

int Nota2(int nota2)
{ 
 nota2=0;
 cout << "\nEntre Segunda Nota: \a";
 cin >> nota2;
 return nota2;
}

int Nota3(int nota3)
{ 
 nota3=0;
 cout << "\nEntre Tercera Nota: \a";
 cin >> nota3;
 return nota3;

}





//funcion promedio
double promedio (int num1, int num2, int num3)
{
double average = 0.0;
average = double(num1 + num2 + num3) / 3.0;


return average;


} //end de la funcion promedio 



int main()
{

	
int Nota1= 0.0;
int Nota2= 0.0;
int Nota3= 0.0;
double average = 0.0;

//llamado a funcion para calcular promedio
average  = promedio(1, 2, 3);
cout << "\nEl Promedio de las 3 Notas es: \a" << average << endl;
cout << "\nPresione Cualquier tecla Para Salir...";


getch();

return 0;
} //end de la funcion main


This post has been edited by Photographer: 19 October 2009 - 09:34 PM

Was This Post Helpful? 0
  • +
  • -

#9 Photographer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-October 09

Re: 3 Grade Average

Posted 19 October 2009 - 08:54 PM

I guess i'm only missing the "call of the functions"
Was This Post Helpful? 0
  • +
  • -

#10 brds  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 76
  • View blog
  • Posts: 515
  • Joined: 22-October 08

Re: 3 Grade Average

Posted 19 October 2009 - 08:59 PM

Ok, the functions nota# do not need you to pass values to them.
/* Prototype */
int Nota1(void);

/* Function */
int Nota1(void) {
    int nota1 = 0;
    cout << "\nEntre Primera Nota: \a";
    cin >> nota1;
    return nota1;
}



After you've made those changes.
average = promedio(Nota1(), Nota2(), Nota3());



If you want I can nitpick some other stuff :D


@edit: capitalization.

This post has been edited by brds: 19 October 2009 - 09:00 PM

Was This Post Helpful? 0
  • +
  • -

#11 Photographer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-October 09

Re: 3 Grade Average

Posted 19 October 2009 - 09:01 PM

^^^As Long as it has the "5 Functions" Go Crazy With It!!!
Was This Post Helpful? 0
  • +
  • -

#12 brds  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 76
  • View blog
  • Posts: 515
  • Joined: 22-October 08

Re: 3 Grade Average

Posted 19 October 2009 - 09:13 PM

You write it, I nitpick. Thats the way it works ;)
Was This Post Helpful? 0
  • +
  • -

#13 Photographer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-October 09

Re: 3 Grade Average

Posted 19 October 2009 - 09:19 PM

You're gonna get a kick out of this one it's running Great!.....Buts it's asking for the third grade first and the first grade for last

It SHOULD say :

"Entre la Primera Nota: "
"Entre la Segunda Nota: "
"Entre la Tercerara Nota: "

And it OUTPUTS:

"Entre la Tercera Nota: "
"Entre la Segunda Nota: "
"Entre la Primera Nota: "

Full "Final Draft?" lol


//funciones promedio

#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <conio.h>
#include <iostream>

using namespace std;


//funciones
double promedio (int, int, int);
int Nota1(void);
int Nota2(void);
int Nota3(void);


//cin de notas
int Nota1(void) {
	int nota1 = 0;
	cout << "\nEntre la Primera Nota: \a";
	cin >> nota1;
	return nota1;
}

int Nota2(void) {
	int nota2 = 0;
	cout << "\nEntre la Segunda Nota: \a";
	cin >> nota2;
	return nota2;
}
int Nota3(void) {
	int nota3 = 0;
	cout << "\nEntre la Tercera Nota: \a";
	cin >> nota3;
	return nota3;
}




//funcion promedio
double promedio (int num1, int num2, int num3)
{
double average = 0.0;
average = double(num1 + num2 + num3) / 3.0;


return average;


} //end de la funcion promedio 



int main()
{
cout << "Riko N. Gonzalez E-00008144\n\a" << endl;
cout << "\nEste progtama Esta hecho Para Calcula el promedio de tres Notas\n" << endl;



int Nota1(void);
int Nota2(void);
int Nota3(void);
double average = 0.0;

//llamado a funcion para calcular promedio
average = promedio(Nota1(), Nota2(), Nota3());
cout << "\nEl Promedio de las 3 Notas es: \a" << average << endl;
cout << "\nPresione Cualquier tecla Para Salir...";


getch();

return 0;
} //end de la funcion main


This post has been edited by Photographer: 19 October 2009 - 09:35 PM

Was This Post Helpful? 0
  • +
  • -

#14 brds  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 76
  • View blog
  • Posts: 515
  • Joined: 22-October 08

Re: 3 Grade Average

Posted 19 October 2009 - 09:37 PM

Silly me.
average = promedio(Nota3(), Nota2(), Nota1());



Nitpicking!!!

The only header you need is iostream, and you only need to include it once.

Prototypes don't go inside of main.

cin.get(); not getch();.

Lastly your indentation needs work.
// Main level
    // One tab
        // Two tabs

int main(void) {
    int a=0;

    if(a)
        cout << "What?" << endl;

    return a;
}


Was This Post Helpful? 0
  • +
  • -

#15 Photographer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-October 09

Re: 3 Grade Average

Posted 19 October 2009 - 09:46 PM

View Postbrds, on 19 Oct, 2009 - 08:37 PM, said:

Silly me.


Nitpicking!!!

The only header you need is iostream, and you only need to include it once.

Prototypes don't go inside of main.

cin.get(); not getch();.

Lastly your indentation needs work.


I Corrected it :rolleyes: ; the headers is bad habit(i always copy & paste the libraries just in case :crazy: ) & Youre Right my indentation SUCKS :v:

Thanks!

This post has been edited by Photographer: 19 October 2009 - 09:47 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2