I'm a beginner, I can't understand the following errors in my c++ program

I'm a beginner, I can't understand the following errors in my c++ program


//This program averages 4 grades and assigns a letter grade based on the numeric average.
#include <iostream>
using namespace std;

int main()

int g1, g2, g3, g4; //Numeric grades to be averaged.

cout << "This program averages 4 grades. n"; // Gathers number inputs to output GPA (Grade Point Average)
cout << "Enter first grade n";
cin >> g1;
cout << "Enter second grade n";
cin >> g2;
cout << "Enter third grade n";
cin >> g3;
cout << "Enter fourth grade n";
cin >> g4;
cout << "Your average is: n";

const int
gpa = ((g1 + g2 + g3 + g4) / 4.0); // Average of g1, g2, g3, and g4.
rep = "Your GPA letter grade is: n"; // Placeholder for the letter grade reply string.

cout << gpa

cout << gpa; // Outputs letter grade string
if (gpa >= 90)
cout << rep "A";
else if (gpa >= 80)
cout << rep "B";
else if (gpa >= 70)
cout << rep "C";
else if (gpa >= 60)
cout << rep "D";
else if (gpa >= 0)
cout << rep "F";
else
cout << "Invalid grade entered, enter positive digits only. n"

system("pause");
return 0;



I receive these error messages:


1>c:userssevensourcereposproject2project2source.cpp(9): error C2144: syntax error: 'int' should be preceded by ';'

1>c:userssevensourcereposproject2project2source.cpp(9): error C2270: 'main': modifiers not allowed on nonmember functions

1>c:userssevensourcereposproject2project2source.cpp(14): error C2062: type 'int' unexpected



I especially don't understand the first error. Why would I ever want a ; to precede int? ";int", and in every case there is an ; preceding "int" on the line before. Sorry if I'm not asking for help properly. Doing my best, thanks!






Can't reproduce the mentioned errors. Are you sure, that this is the code, that you are compiling? There are plenty of other errors, which are pretty clear in my opinion, though.

– Algirdas Preidžius
Sep 10 '18 at 23:33







The error messages do not appear to match the source you posted. It looks like you posted a different version of the source than was used to produce those error messages. You should fix that before any questions can be answered. (Did you change the source file in an editor and not save it before compiling? That is one reason the source you see could differ from the source being compiled.)

– Eric Postpischil
Sep 10 '18 at 23:34







Note you're missing a semi-colon on cout << gpa, but that wouldn't cause those errors.

– Tas
Sep 10 '18 at 23:36


cout << gpa




1 Answer
1


#include <iostream>

using namespace std;

int main()

int g1, g2, g3, g4; //Numeric grades to be averaged.

cout << "This program averages 4 grades. n"; // Gathers number inputs to output GPA (Grade Point Average)
cout << "Enter first grade n";
cin >> g1;
cout << "Enter second grade n";
cin >> g2;
cout << "Enter third grade n";
cin >> g3;
cout << "Enter fourth grade n";
cin >> g4;
cout << "Your average is: n";

const int gpa = ((g1 + g2 + g3 + g4) / 4.0); // Average of g1, g2, g3, and g4.
const string rep = "Your GPA letter grade is: n"; // Placeholder for the letter grade reply string.

cout << gpa;

cout << gpa; // Outputs letter grade string
if (gpa >= 90)
cout << rep << "A";
else if (gpa >= 80)
cout << rep << "B";
else if (gpa >= 70)
cout << rep << "C";
else if (gpa >= 60)
cout << rep << "D";
else if (gpa >= 0)
cout << rep << "F";
else
cout << "Invalid grade entered, enter positive digits only. n";

system("pause");
return 0;



Please check your syntax. All errors were caused by the syntax error.






you shouldn't concatenate in cout << rep + "A"; you should use << instead.

– Muzol
Sep 10 '18 at 23:44



cout << rep + "A";


<<






@Muzol thank you for revision

– R.Roh
Sep 10 '18 at 23:46



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

Node.js puppeteer - Use values from array in a loop to cycle through pages