// The purpose of this Lab is to start the program used in Lab 1 and modify it
// to calculate the average of 4 grades entered by the user and display the results
// on the console through the use of the math operators in C++.

// Part 2 of the Lab The modify the program of Part 1 to calculate a final grade out 100% from the following data:
// Grades 1 & 2 are Quiz grades out of 10 points and count for 15% of the final grade.
// Grade 3 is a term paper, graded with an A, B C, D or F where A = 95, B = 85, C = 75, D = 65 and F = 55, and count for 40% of the final grade.
// Grade 4 is the number of points received on the final. The final exam was out of 75 total points and is 45% of the final grade.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main ()
{
int G1;
int G2;
int G3;
int G4;

cout << " This program will average 4 grades entered by " << endl;
cout << " the user and display the ouput on the console. " << endl;
cout << " Do not enter characters, such as A, B or C into " << endl;
cout << " the input, use only numbers 1-100 " << endl;

cin >> G1;

cin >> G2;

cin >> G3;

cin >> G4;

cout << " The average is " << endl;
cout << (G1 + G2 + G3 + G4)/ 4;

int

}

Edited by Nick Evan: Added code-tags

4
Contributors
20
Replies
21
Views
6 Years
Discussion Span
Last Post by Valaraukar
Featured Replies
• 1

[QUOTE=kra9853]I've fixed all the prompt errors now i'm having issues figuring out how to assign percentages of the 4 grades[/QUOTE] Lines 6, 19, and 20. Look at the variable type. Look at what you are asking the user to enter. int versus char. They need to match. If you are …

Are you actually asking for some help here or just expecting people to do your homework for you? You won't learn anything if people do all the work for you. If you actually need help with a programming issue and have at least made an attempt to solve your own problems then I imagine people would be more inclined to help you.

Im not asking for you to do it, I'm asking how can I assign character grades to one of my variables and how to evaluate grades 1,2 & 4 out of a certain grade to be averaged out. I'm sorry if I offended you in anyway, I really want to get a hang C++ ive just hit a wall of programming, perhaps i should modify it piece by piece instead of looking at the whole picture, what do u think?

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main ()
{
int G1;
int G2;
int G3;
int G4;

cout << " This program will average 4 grades entered by " << endl;
cout << " the user and display the ouput on the console. " << endl;
cout << " Do not enter characters, such as A, B or C into " << endl;
cout << " the input, use only numbers 1-100 " << endl;

cin >> G1;

cin >> G2;

cin >> G3;

cin >> G4;

cout << " The average is " << endl;
cout << (G1 + G2 + G3 + G4)/ 4;

int  A=95,
int  B=85,
int  C=75,
int  D=65,
int  F=55,

}

Edited by kra9853: I think there has been a misunderstanding, I did make an attempt on the problem

I going to first modify my program to give me the percentages of my grades and then later assign characters for grade 3 sooo lets see how this turns out...

1. Tell the user exactly what they need to enter for input.
2. Verify that the input is good. If not, give them an appropriate error message and prompt them again.
3. Convert THEIR input into something that you can stick into a formula and calculate.
4. Give the output based on the formula calculation.

Regarding #2, ask your professor whether this needs to be implemented. You may be allowed to assume valid data.

Regarding #1, I interpret the instructions as wanting this as input:

1. A number from 0 to 10 for grades 1 and 2.
2. A letter 'A', 'B', 'C', 'D', or 'F' for grade 3.
3. A number from 0 to 75 for grade 4.

If my interpretation is correct, your prompt here is invalid for grade #3:

Do not enter characters, such as A, B or C

use only numbers 1-100

Valid ranges are 0 to 10 for grades 1 and 2, and 0 - 75 for grade 4. Entering 100 is invalid for all of them, so don't tell them they can do that. Explain in the prompt EXACTLY what you want from them. Regardless, the formula is going to be a lot more complicated than this:

(G1 + G2 + G3 + G4)/ 4;

Keep in mind that we don't know what "Lab 1" was, so if this is leftover code from that, all it's going to do is confuse us.

Yes taking things a piece at a time is a good idea :) as suggested in the previous post you should also be careful with you cout statements because it is unclear to the user what input you actually require.
For example, for grade 1 you may change

cout << " Enter your first grade:" << endl;

to something along the lines:

cout << " Please enter your grade 1 result (integers from 0 to 10)"

I don't know how important it is for you to validate user input but it is always a good idea to do so (it shows you know how and is good practice). Check out this link.

If your struggling with writing the calculations in terms of code, then perhaps first try just doing the calculations with pen and paper and converting to code after. If this fails then maybe try converting to pseudo code and then finally to code :) I doubt you'll need to for this particular problem however ;)

Oh and also, seeing as the average of the grades may not be an integer value perhaps you should consider changing your integer division to:

cout << (G1 + G2 + G3 + G4)/ 4.0;

Edited by Valaraukar: n/a

I've fixed all the prompt errors now i'm having issues figuring out how to assign percentages of the 4 grades

int main ()
{
//This declares the variables (the 4 grades) for the program
int G1;
int G2;
int G3;
int G4;
//Instructions that prompt the user on the console
cout << " This program will average 4 grades entered by " << endl;
cout << " the user and display the ouput on the console. " << endl;

cout << " Enter your first grade (integers from 0 to 10):" << endl;
cin >> G1;

cout << " Enter your second grade (integers from 0 to 10):" << endl;
cin >> G2;

cout << " Enter your third grade (characters case sensitive A-F):" << endl;
cin >> G3;

cout << " Enter your fourth grade (integers from 0 to 75):" << endl;
cin >> G4;

cout << " The grade is... " << endl;
cout << (G1 + G2 + G3 + G4)/ 4.0;

my professor hinted that we should use the iomanip library and use setprecisions and fixed functions but i have no clue how to implement it into my code correctly :(

I've fixed all the prompt errors now i'm having issues figuring out how to assign percentages of the 4 grades

Lines 6, 19, and 20. Look at the variable type. Look at what you are asking the user to enter. int versus char. They need to match. If you are reading in a char, you should read it into a character variable. Then you need to convert it from a character to an integer in order to do a formula.

Line 26 : As mentioned, the formula is going to be a lot more complicated. You don't need to do it all in one step. Have intermediate steps and intermediate variables. The formula is going to involve all of the numbers your professor listed. That's too much to stick in one single calculation statement. Calculate it on paper, then convert the process to C++.

my professor hinted that we should use the iomanip library and use setprecisions and fixed functions but i have no clue how to implement it into my code correctly

That's a display/output problem. Worry about that when you get an actual, accurate number to display. One thing at a time. You need to get an actual answer first.

Edited by VernonDozier: n/a

Supportive writing is always good!

Ok so firstly the <iomanip> problem. Here are two useful links (one two)

Once you know the functions you have to work with you can simply google for some example uses :) The one here shows a very clear example of using the setprecision function.

Now to actually tackle the percentage conversions. If your unsure about how to actually calculate the percentages then I suggest browsing the internet for a few examples and explanations on percentage calculations; or of course you could check out some books. Just googling "converting grade to percentage" should provide some useful info.

If you are supposed to be converting G3 from a char to a numerical value then the first step is to change G3's declaration.

char G3;

Then there are numerous options to determine the equivalent grade. As mentioned by Vernon you should probably convert from a char to an int but you could also try other things if you don't like the conversion method (although I would recommend it).
You could try basic 'if' statements to check for particular characters and then grab a corresponding value. e.g.

int exampleGrade;

if( G3 == 'A' || G3 == 'a' )
{
}

This code is very unsafe however so it would be much better to use the char conversion method ;)

Edited by Valaraukar: n/a

good suggestion

I am very new . I wrote on my own. pls check

#include <cstdlib>
#include <iostream>
#include <conio.h>

using namespace std;

int main(int argc, char *argv[])
{
int G1;
int G2;
char G3;
int G4;
float final,mean1,mean2,mean3;

cin >> G1;
cin >> G2;
mean1=0.15*(G1+G2)/2;
cin >> G3;
if (G3 == 'A') mean2=0.40*95;
if (G3 == 'B') mean2=0.40*85;
if (G3 == 'C') mean2=0.40*75;
if (G3 == 'D') mean2=0.40*65;
if (G3 == 'E') mean2=0.40*55;
cin >> G4;
mean3=0.45*G4;

final = mean1+ mean2 + mean3;
cout << "final=" << final;

getch();
}

burcin you should use the code tags when you post code otherwise it's hard to read and looks bad. I don't believe that individual test/quiz percentages were actually required but it's never bad to do a little extra :)
There is a much more efficient way of calculating the users overall percentage however. I imagine that is why the first task was set

calculate the average of 4 grades entered by the user

If you can determine the total number of marks available for all four tests and you have the average then you can work out the final percentage.

Edited by Valaraukar: n/a

thanks guys for all the help i recruited some help from an old programmer and i made a third attempt lol but i'm still getting syntax errors, i might try caged fire's approach cause ive seen it used in class before, but at the moment this is what ive made,

// Lab2_Abercrombie3.0.cpp : Defines the entry point for the console application.
// Written by Kevin Abercrombie
// The purpose of this Lab is to start the program used in Lab 1 and modify it
// to calculate the average of 4 grades entered by the user and display the results
// on the console through the use of the math operators in C++.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main ()
{
//This declares the variables (the 4 grades) for the program
int G1, G2, G3, G4;
int Ga;
string Letter3;
int Gb;
int Gc;

//Instructions that prompt the user on the console
cout << " This program will average 4 grades entered by " << endl;
cout << " the user and display the ouput on the console. " << endl;

cout << " Enter your first grade (integers from 0 to 10):" << endl;
cin >> G1;

cout << " Enter your second grade (integers from 0 to 10):" << endl;
cin >> G2;

int sum = G1 + G2;
Ga = sum * .15;

cout << " Enter your third grade (characters case sensitive A-F):" << endl;
cin >> Letter3;
if(input.equals(“A”)){
G3 = 95;
}
if(input.equals(“B”){
G3 = 85;
}
if(input.equals(“C”){
G3 = 75;
}
if(input.equals(“D”){
G3 = 65;
}
if(input.equals(“F”){
G3 = 55;
}

Gb = G3 *.4;

cout << " Enter your fourth grade (integers from 0 to 75):" << endl;
cin >> G4;
Gc = G4 *.45;

cout << " The grade is... " << endl;
cout << Ga + Gb + Gc;

}

Step away from the computer and calculate a perfect score with pencil and paper. If you can't do that with pencil and paper, you need to get the math straight first. Do not skip any steps. Now look at all the numbers on the paper and make sure they're in the program too. I don't see the number 75 anywhere in your program save for the prompt. Surely that's needed somewhere or the professor wouldn't have given it to you.

Its telling me my "if" statements are fudged and my characters are unidentified so mayb should i try this,

if ("A") {G3 = 95};
if ("B') {G3 = 85};

pls check

Surely you've checked yourself and realize this won't compile?

Its telling me my "if" statements are fudged and my characters are unidentified so mayb should i try this,

Compilers don't use the word "fudged". We need an error message with a corresponding line number. Specificity is key.

If something is unidentified, then you need to identify it. It will tell you exactly what variable name it can't identify. Look at you code and make sure you've declared it. If not, declare it and recompile.

Specific enough? lol

1>------ Build started: Project: Lab2_Abercrombie3.0, Configuration: Debug Win32 ------
1>Build started 9/23/2010 5:03:28 PM.
1>InitializeBuildStatus:
1> Touching "Debug\Lab2_Abercrombie3.0.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1> Lab2_Abercrombie3.0.cpp
1>c:\users\kevin abercrombie\documents\visual studio 2010\projects\lab2_abercrombie3.0\lab2_abercrombie3.0\lab2_abercrombie3.0.cpp(18): error C2144: syntax error : 'int' should be preceded by ';'
1>c:\users\kevin abercrombie\documents\visual studio 2010\projects\lab2_abercrombie3.0\lab2_abercrombie3.0\lab2_abercrombie3.0.cpp(36): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>c:\users\kevin abercrombie\documents\visual studio 2010\projects\lab2_abercrombie3.0\lab2_abercrombie3.0\lab2_abercrombie3.0.cpp(39): error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1053): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,signed char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1060): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,signed char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1067): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,unsigned char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1074): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,unsigned char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1097): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1104): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1111): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1118): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1128): or 'std::basic_istream<_Elem,_Traits> &std::operator >><char,std::char_traits<char>,std::string>(std::basic_istream<_Elem,_Traits> &&,_Ty &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ty=std::string
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(179): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(185): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(192): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(199): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(218): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(253): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(272): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(298): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(316): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(334): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned long &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(354): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(373): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(392): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(float &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(411): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(429): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(447): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(void *&)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(466): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> while trying to match the argument list '(std::istream, std::string)'
1>c:\users\kevin abercrombie\documents\visual studio 2010\projects\lab2_abercrombie3.0\lab2_abercrombie3.0\lab2_abercrombie3.0.cpp(40): error C2065: 'A' : undeclared identifier
1>c:\users\kevin abercrombie\documents\visual studio 2010\projects\lab2_abercrombie3.0\lab2_abercrombie3.0\lab2_abercrombie3.0.cpp(43): error C2065: 'B' : undeclared identifier
1>c:\users\kevin abercrombie\documents\visual studio 2010\projects\lab2_abercrombie3.0\lab2_abercrombie3.0\lab2_abercrombie3.0.cpp(46): error C2065: 'C' : undeclared identifier
1>c:\users\kevin abercrombie\documents\visual studio 2010\projects\lab2_abercrombie3.0\lab2_abercrombie3.0\lab2_abercrombie3.0.cpp(49): error C2065: 'D' : undeclared identifier
1>c:\users\kevin abercrombie\documents\visual studio 2010\projects\lab2_abercrombie3.0\lab2_abercrombie3.0\lab2_abercrombie3.0.cpp(52): error C2065: 'F' : undeclared identifier
1>c:\users\kevin abercrombie\documents\visual studio 2010\projects\lab2_abercrombie3.0\lab2_abercrombie3.0\lab2_abercrombie3.0.cpp(56): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>c:\users\kevin abercrombie\documents\visual studio 2010\projects\lab2_abercrombie3.0\lab2_abercrombie3.0\lab2_abercrombie3.0.cpp(61): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:05.20
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Edited by kra9853: n/a

Specific enough? lol

Nope. Not specific at all. One error, one line number, one exact error message. I was looking for this one, which I didn't find in that mess you dumped.

1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(40) : error C2065: 'input' : undeclared identifier

After I got rid of stdafx.h and #included the string library, things got more manageable.

1>------ Build started: Project: daniweb.cpp, Configuration: Debug Win32 ------
1>Compiling...
1>daniweb.cpp
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(36) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(40) : error C2065: 'input' : undeclared identifier
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(40) : error C2228: left of '.equals' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(43) : error C2065: 'input' : undeclared identifier
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\dummy.cpp\dummy.cpp(43) : error C2228: left of '.equals' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(43) : error C2143: syntax error : missing ')' before '{'
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(46) : error C2065: 'input' : undeclared identifier
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(46) : error C2228: left of '.equals' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(46) : error C2143: syntax error : missing ')' before '{'
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(49) : error C2065: 'input' : undeclared identifier
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(49) : error C2228: left of '.equals' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(49) : error C2143: syntax error : missing ')' before '{'
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(52) : error C2065: 'input' : undeclared identifier
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(52) : error C2228: left of '.equals' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(52) : error C2143: syntax error : missing ')' before '{'
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(56) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>c:\users\vern\documents\visual studio 2008\projects\daniweb\daniweb\daniweb.cpp(61) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>Build log was saved at "file://c:\Users\vern\Documents\Visual Studio 2008\Projects\daniweb\daniweb\Debug\BuildLog.htm"
1> - 14 error(s), 3 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

And here's the nice, formatted code. As a side benefit, it's no longer encoded in UTF-16 or whatever you had it in. Code Blocks couldn't figure out what it was.

// Lab2_Abercrombie3.0.cpp : Defines the entry point for the console application.
// Written by Kevin Abercrombie
// The purpose of this Lab is to start the program used in Lab 1 and modify it
// to calculate the average of 4 grades entered by the user and display the results
// on the console through the use of the math operators in C++.

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main ()
{
//This declares the variables (the 4 grades) for the program
int G1, G2, G3, G4;
int Ga;
string Letter3;
int Gb;
int Gc;

//Instructions that prompt the user on the console
cout << " This program will average 4 grades entered by " << endl;
cout << " the user and display the ouput on the console. " << endl;

cout << " Enter your first grade (integers from 0 to 10):" << endl;
cin >> G1;

cout << " Enter your second grade (integers from 0 to 10):" << endl;
cin >> G2;

int sum = G1 + G2;
Ga = sum * .15;

cout << " Enter your third grade (characters case sensitive A-F):" << endl;
cin >> Letter3;
if(input.equals("A")){
G3 = 95;
}
if(input.equals("B"){
G3 = 85;
}
if(input.equals("C"){
G3 = 75;
}
if(input.equals("D"){
G3 = 65;
}
if(input.equals("F"){
G3 = 55;
}

Gb = G3 *.4;

cout << " Enter your fourth grade (integers from 0 to 75):" << endl;
cin >> G4;
Gc = G4 *.45;

cout << " The grade is... " << endl;
cout << Ga + Gb + Gc;
}

When you get all of those linker errors, you usually are missing a bracket or a semicolon or haven't included a header or your project isn't set up right or something like that. Always #include string if you're using strings, even if the compiler lets you get away with it.

Edited by VernonDozier: n/a

Where is your declaration for input kra?
With the newly posted code, courtesy of Vernon, nearly all errors are taken care of except for one referring to a missing 'input' declaration. Once you've fixed that I think you should be sorted ;)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.