LNK2019 unresolved external symbol "int __cdecl examAvg(void)" - c++

When I try to compile, I get only two error messages.
"Error LNK2019 unresolved external symbol "int __cdecl examAvg(void)" (?examAvg##YAHXZ) referenced in function _main
Line 1
and
LNK1120 1 unresolved externals
also on Line 1
I have worked on this so long (days) that I really can't figure out where I am going wrong anymore, I am sure it is something simple, but I am for a loss again.
Will someone please give me a suggestion to help rectify the error codes?
/*
Christopher Pierce
Date Created: July 3, 2020
Egrades Vector Application
*This application creates a C++ menu program that generates an electronic grade sheet that can keep track of five student test scores earned during the semester.
• Organizes the main program menu to call four functions.
• (1) function that allow a user to Add five students and their scores on three exams into the vector.
• (2) function that will compute the average test score for each of the five students in the vector.
• (3) function that all the user to display a student average test scores searching for their name in the vector.
• (4) function that will compute the average of the average exams in the vector and display the result.
*/
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
// Declarations
int score1;
int score2;
int score3;
int score4;
int score5;
int score6;
int score7;
int score8;
int score9;
int score10;
int score11;
int score12;
int score13;
int score14;
int score15;
string student1;
string student2;
string student3;
string student4;
string student5;
int main()
{
vector <string> StudentFile;
vector <int> Egrades;
int average1 = (score1 + score2 + score3) / 3;
int average2 = (score4 + score5 + score6) / 3;
int average3 = (score7 + score8 + score9) / 3;
int average4 = (score10 + score11 + score12) / 3;
int average5 = (score13 + score14 + score15) / 3;
// Prototype (functions)
int examAvg();
{
StudentFile.insert(StudentFile.begin(), student1);
Egrades.insert(Egrades.begin(), average1);
StudentFile.push_back(student2);
Egrades.push_back(average2);
StudentFile.push_back(student3);
Egrades.push_back(average3);
StudentFile.push_back(student4);
Egrades.push_back(average4);
StudentFile.push_back(student5);
Egrades.push_back(average5);
}
/*
Start of Menu
*/
// Defines the width of the menu
const int menuWidth = 84;
// This is a loop structure for the menu box using ASCII
// This prints the top left corner of the menu box (ASCII)
cout << char(201);
// This prints the top border of the menu box (ASCII)
for (int column = 0; column < menuWidth; ++column) {
cout << char(205);
}
// This prints the top right corner of the menu box (ASCII)
cout << char(187);
cout << "\n";
// array with menu options
string menu[15];
menu[0] = " **************";
menu[1] = " *** MAIN MENU ***";
menu[2] = " **************";
menu[3] = " Please Choose From The Following Options:";
menu[6] = " 1. Add 5 Students to Egrades Vector:";
menu[8] = " 2. Compute Student Test Score Average:";
menu[10] = " 3. Search A Student Average Test Score:";
menu[12] = " 4. Compute The Average Of All 5 Student Exam Averages:";
menu[14] = " 5. Exit";
for (string option : menu)
{
cout << char(186) // print left border
<< setw(menuWidth) // set next item width
<< left // set next item aligment
<< option // print menu option string with width and aligment
<< char(186) << "\n"; // print right border
}
// This will print the bottom left corner of the menu box (ASCII)
cout << char(200);
// This prints the bottom border of the menu box (ASCII)
for (int column = 0; column < menuWidth; ++column) {
cout << char(205);
}
// This prints the bottom right corner of the menu box (ASCII)
cout << char(188);
cout << "\n\n";
/*
END OF MENU
*/
char selection;
cout << "\t\t\t Enter Your Selection: ", cin >> selection, cout << endl;
switch (selection)
{
case '1':
system("CLS");
cout << "Student Information Section:\n\n";
// Student 1 Info, captures name and scores
cout << "\nEnter Student 1 Name: \n";
cin >> student1;
cout << "\nEnter Exam 1 Score: ";
cin >> score1;
cout << "Enter Exam 2 Score: ";
cin >> score2;
cout << "Enter Exam 3 Score: ";
cin >> score3; examAvg();
// Student 2 Info, captures name and scores
cout << "\nEnter Student 2 Name:\n";
cin >> student2;
cout << "\nEnter Exam 1 Score: ";
cin >> score4;
cout << "Enter Exam 2 Score: ";
cin >> score5;
cout << "Enter Exam 3 Score: ";
cin >> score6; examAvg();
// Student 3 Info, captures name and scores
cout << "\nEnter Student 3 Name:\n";
cin >> student3;
cout << "\nEnter Exam 1 Score: ";
cin >> score7;
cout << "Enter Exam 2 Score: ";
cin >> score8;
cout << "Enter Exam 3 Score: ";
cin >> score9; examAvg();
// Student 4 Info, captures name and scores
cout << "\nEnter Student 4 Name:\n";
cin >> student4;
cout << "\nEnter Exam 1 Score: ";
cin >> score10;
cout << "Enter Exam 2 Score: ";
cin >> score11;
cout << "Enter Exam 3 Score: ";
cin >> score12; examAvg();
// Student 5 Info, captures name and scores
cout << "\nEnter Student 5 Name:\n";
cin >> student5;
cout << "\nEnter Exam 1 Score: ";
cin >> score13;
cout << "Enter Exam 2 Score: ";
cin >> score14;
cout << "Enter Exam 3 Score: ";
cin >> score15; examAvg();
cout << "\n\n******************************************************\n";
cout << "!!! INFORMATION HAS BEEN ADDED TO EGRADES VECTOR !!!\n";
cout << "******************************************************\n\n";
cout << "To Return To Main Menu:\n\n";
system("pause");
return main();
break;
case '2':
system("CLS");
for (unsigned int i = 0; i < Egrades.size(); ++i)
{
cout << Egrades[i] << endl;
}
cout << "To Return To Main Menu:\n\n";
system("pause");
return main();
break;
case '3':
system("CLS");
int score;
cout << "\nEnter A Students Name To Find Their Average:\n";
cin >> score;
if (cin >> student1)
{
cout << "Average Found:\n" << average1;
}
else if (cin >> student2)
{
cout << "Average Found:\n" << average2;
}
else if (cin >> student3)
{
cout << "Average Found:\n" << average3;
}
else if (cin >> student4)
{
cout << "Average Found:\n" << average4;
}
else if (cin >> student5)
{
cout << "Average Found:\n" << average5;
}
else
{
cout << "Average not found.\n";
}
cout << "To Return To Main Menu:\n\n";
system("pause");
return main();
break;
case '4':
system("CLS");
cout << "The Average of All Five Students Averages Are:\n\n";
cout << "|| " << (average1 + average2 + average3 + average4 + average5) / 5 << " ||\n\n";
cout << "To Return To Main Menu:\n\n";
system("pause");
return main();
break;
case '5':
exit(-1);
break;
default: cout << "\n Invalid selection\n\n";
}
return 0;
}

Related

Is there a way to add names of 5 students with 3 exams scores each to a vector?

I am lost again, I know that there is a way to use push_back to add to the vector, but I am at a loss for how I can actually get it to work. What I am trying to do is add 5 students to a vector (Egrades), and with each student gather 3 separate exam scores and attach them to that students name so that I can compute the averages later.
In my code below, I took out the lines in the cases, and only put student 1 to cut down length.
Where am I going wrong? Did I forget to put something in?
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void)
{
// Delcarations
int score1;
int score2;
int score3;
int scores[5];
vector <int> Egrades;
string student1;
string student2;
string student3;
string student4;
string student5;
// array with menu options
string menu[15];
menu[0] = " **************";
menu[1] = " *** MAIN MENU ***";
menu[2] = " **************";
menu[3] = " Please Choose From The Following Options:";
menu[6] = " 1. Add Student:";
menu[8] = " 2. Compute Student Test Score Average:";
menu[10] = " 3. Search A Student Average Test Score:";
menu[12] = " 4. Compute The Average Of The Average Exams:";
menu[14] = " 5. Exit";
char selection;
cout << "\t\t\t Enter Your Selection: ", cin >> selection, cout << endl;
switch (selection)
{
case '1':
system("CLS");
do
{
{
cout << "Student Information Section:\n\n";
// Student 1 Info
cout << "Enter Student 1 Name:\n";
cin >> student1; cout << endl;
cout << "Enter Exam 1 Score: ";
cin >> score1; cout << endl;
cout << "Enter Exam 2 Score: ";
cin >> score2; cout << endl;
cout << "Enter Exam 3 Score: ";
cin >> score3; cout << "\n" << endl;
}
system("pause");
return main();
}
while (cin >> score1, score2, score3);
break;
case '2':
break;
case '3':
break;
case '4':
break;
case '5':
exit(-1);
break;
default: cout << "\n Invalid selection\n\n";
}
return 0;
}

How to fix this structure string function C++? [duplicate]

This question already has answers here:
Why does std::getline() skip input after a formatted extraction?
(5 answers)
Closed 2 years ago.
I have a kind of odd problem with my function inputData. It works fine for the first movie's input. However, when it goes to do the second movie it skips over asking you to enter in the second movie's name and goes straight to prompting you to enter in the second movie's sales. The movie's name needs to be able to include spaces.
Any ideas? Anything is greatly appreciated. Thank you
struct Movie{
string movieName;
double firstWeek;
double secondWeek;
double thirdWeek;
double fourthWeek;
double total;
double avg;
};
// prototypes
void dispMenu();
char menuChoice();
void inputData(Movie *mov);
float getValidSale();
void TotalAvgSales(Movie *mov);
void displayMovieData(Movie mov);
int main() {
cout << "Welcome to Movie Data\n";
// movie 1 and 2 structure variables
Movie movie1, movie2;
char choice = 'B';
do { // loop while not D
choice = menuChoice(); // get menu choice
switch (choice) // menu options
{
case 'A':
case 'a':
// input for first movie
cout << "First Movie\n";
inputData(&movie1);
// input for second movie
cout << endl << "Second Movie\n";
inputData(&movie2);
break;
case 'B':
case 'b':
// compute for movie 1
TotalAvgSales(&movie1);
// compute for movie 2
TotalAvgSales(&movie2);
cout << "Completed!\n";
break;
case 'C':
case 'c':
// display for first movie
cout << "First Movie\n";
displayMovieData(movie1);
// display for second movie
cout << "Second Movie\n";
displayMovieData(movie2);
case 'd':
exit;
}
} while (choice != 'D');
}
// displays the menu
void dispMenu(){
cout << "Menu Options:\n";
cout << "A) Add Data\n";
cout << "B) Compute Total and Avg\n";
cout << "C) Display Data\n";
cout << "D) Quit\n";
}
// gets menu choice and verifies that it is valid input
char menuChoice(){
char choice; // option selected
dispMenu(); // displays menu
cin >> choice;
choice = toupper(choice); // if they enter lowercase, changes it to uppercase
cin.ignore(1, '\n'); // ignores input buffer
while ( choice < 'A' || choice > 'D') // make sure it is A B C or D
{
dispMenu(); // display menu
cin >> choice;
choice = toupper(choice); // if enter lower case, make upper case
cin.ignore(1, '\n'); // ignore input buffer
}
return choice;
}
float getValidSale(){
float sale;
cout << "Please enter in the number of tickets sold...\n";
cin >> sale;
while ( sale < 0){
cout << "Please enter in the number of tickets sold (>0)...";
cin >> sale;
}
return sale;
}
here is the problem function below
void inputData(Movie *mov){
// enter movie name
cout << "Please enter in Movie name...";
getline (cin, mov->movieName);
// enter first week sales
cout << "First Week Number of Tickets Sold...\n";
cout << "Please enter the number of tickets sold...";
cin >> mov->firstWeek;
// verify input >0a
while(mov->firstWeek < 0){
cout << "Please enter in the number of tickets sold (>0)...";
cin >> mov->firstWeek;
}
// enter second week sales
cout << "Second Week Number of Tickets Sold...\n";
cout << "Please enter the number of tickets sold...";
cin >> mov->secondWeek;
// verify input >0
while(mov->secondWeek < 0){
cout << "Please enter in the number of tickets sold (>0)...";
cin >> mov->secondWeek;
}
// enter third week sales
cout << "Third Week Number of Tickets Sold...\n";
cout << "Please enter the number of tickets sold...";
cin >> mov->thirdWeek;
// verify input >0
while(mov->thirdWeek < 0){
cout << "Please enter in the number of tickets sold (>0)...";
cin >> mov->thirdWeek;
}
// enter second week sales
cout << "Fourth Week Number of Tickets Sold...\n";
cout << "Please enter the number of tickets sold...";
cin >> mov->fourthWeek;
// verify input >0
while(mov->fourthWeek < 0){
cout << "Please enter in the number of tickets sold (>0)...";
cin >> mov->fourthWeek;
}
}
// calculate the average sales
void TotalAvgSales(Movie *mov){
// adding up the sales of each week
mov -> total = mov->firstWeek + mov->secondWeek + mov->thirdWeek + mov->fourthWeek;
// finding the average
mov -> avg = mov->total/4;
}
// display the data
void displayMovieData(Movie mov)
{
cout << fixed << setprecision(2);
cout << "First Movie\n";
cout << "Division Name: " << mov.movieName << endl;
cout << "First Quarter Sales: "<< mov.firstWeek << endl;
cout << "Second Quarter Sales: "<< mov.secondWeek << endl;
cout << "Third Quarter Sales: " << mov.thirdWeek << endl;
cout << "Fourth Quarter Sales: "<< mov.fourthWeek << endl;
cout << "Total Number of Tickets Sold: " << mov.total << endl;
cout << "Average Number of Tickets Sold: " << mov. avg << endl;
}
I believe I fixed it. Right above the
getline (cin, mov->movieName);
i added a
cin.clear();
and a
cin.ignore();
This seems to work.

How to display user account only using user ID num

Im basically making a database that stores a users account info. (Name, Phone number, ID, etc) I want to be able to display a specific persons info by entering in their ID num.
I have a struct with basic info and an array struct that stores each person and their info. I need to be able to type in a persons ID and have it display their info.
(I am still in first year of CS degree plz be gentle lol)
struct Account{
string name;
string city;
string state;
int ZIP;
int phone;
int IDNUM;
double ACT_BAL;
string LST_PMNT;};
Main fuction
const int SIZE = 20;
Account customers[SIZE];
const int NEW_INFO = 1, CHNG_INFO = 2, DISP = 3, EXIT = 4;
char choice1;
int choice;
int n;
int NEWCUST;
int results;
do
{ // menu display
cout << "Customer Database\n"
<< "----------------------------\n"
<< "1. Enter new account info\n"
<< "2. Change account info\n"
<< "3. Display all account info\n"
<< "4. Exit\n";
cin >> choice;
//respond to user input
switch (choice)
case NEW_INFO:
cout << "Would you like to enter a new cusomter?\n"
<< "(Y/N)";
cin >> choice1;
if (choice1 == 'Y' || choice1 == 'y')
{
cout << "How many new customers?" << endl; //User eneters in new customer info without having to enter in a full array worth of customers.
cin >> NEWCUST;
for (n = 0; n < NEWCUST; n++)
{
cout << "ID Number: ";
cin >> customers[n].IDNUM;
cout << "Enter in a name: ";
cin >> customers[n].name;
cout << "City: ";
cin >> customers[n].city;
cout << "State: ";
cin >> customers[n].state;
cout << "ZIP code: ";
cin >> customers[n].ZIP;
cout << "Phone number: ";
cin >> customers[n].phone;
cout << "Account Balance: ";
cin >> customers[n].ACT_BAL;
cout << "Lasy payment date: ";
cin >> customers[n].LST_PMNT;
}
}
break;
case CHNG_INFO: // Changes info
break; // displays all info (work in progress)
case DISP:
cout << "Enter customers ID number" << endl;
cin >> customers[].IDNUM;
results = linearSearch(customers, SIZE, customers[].IDNUM);
break;
case EXIT:
cout << "Cosing......" << endl; //exits progeam
break;
To get a specific user details, you can do the following:
Declaring num as short int to hold a simple User ID, you can change it. N = 50 as you've provided the constant. Now, unless the loop finds the inputted ID matching with one of the struct's idNum, it'll be executed 50 times (max).
cout << "Input account code: ";
cin >> num;
for (int i = 0; i < N; i++)
{
if (num == acc[i].idNum)
{
cout << "Name: " << acc[i].name << endl
<< "..." << endl;
}
}

How would i reject invalid inputs in my code?

I have no idea how i would reject invalid inputs for the exams and assignments (valid numbers are 0.00 - 100.00). but i also need to give the user one more chance to enter a valid input. so if they put in two invalid inputs in a row for the same variable it tells the user that they need to restart the program and prevent it from running. Im new to programming so im not very good at this.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main ()
{
float exam_1;
float exam_2;
float exam_3;
float assignment_1;
float assignment_2;
float weighted_exam = .1667;
float weighted_assignment = .25;
float min_score = 0.00;
float max_score = 100.00;
string name;
cout << "Please enter student name <First Last>: "; // this will ask for the students first and last name
getline(cin, name);
cout << "\n";
cout << "\t Be sure to include the decimal point for scores.\n";
cout <<"\t !!! All scores should range from 0.00 to 100.00!!! \n";
cout << "\t For example: 80.50 \n";
cout << "\n";
cout << "Please enter your exam 1 score: ";
cin >> exam_1;
cout << "Please enter your exam 2 score: ";
cin >> exam_2;
cout << "Please enter your exam 3 score: ";
cin >> exam_3;
cout << "Please enter your assignment 1 score: ";
cin >> assignment_1;
cout << "Please enter your assignment 2 score: ";
cin >> assignment_2;
cout << endl;
cout << "-" << "OUTPUT" << "-\n";
return 0;
}
You can do like this:
do{
cout <<"\t !!! All scores should range from 0.00 to 100.00!!! \n";
cin >> exam_1;
while(exam_1 < 0.0 || exam_1>100.0);
Repeat this to all inputs
cout << "Please enter your exam 1 score: ";
cin >> exam_1;
cout << "Please enter your exam 2 score: ";
cin >> exam_2;
cout << "Please enter your exam 3 score: ";
cin >> exam_3;
To
auto ReadExamScore = [](auto& ex, char c)
{
cout << "Please enter your exam " << c << " score: ";
for (int i = 0; i < 2; i ++)
{
if (cin >> ex)
{
if (ex>= 0.0 && ex <= 100.00)
return true;
}
cout << "Please enter a valid exam score" << endl;
}
cout << "Press any key to exit..." << endl;
getchar();
exit(0);
};
ReadExamScore(exam_1,'1');
ReadExamScore(exam_2,'2');
ReadExamScore(exam_3,'3');

Array not initializing properly within a while loop

My issue is that I have set up an array to store totals that were calculated from values read from a file. These stored totals are then added together to find the over all average.
This issue is stemming from a 'cin' at the beginning of the program where the user inputs a number and that number is supposed to drive the program by setting how many times the program loops and how many modules are inside the array. The array does not seem to work properly no matter how much I try.
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string StudentGrades;
int studentID;
double quiz1;
double quiz2;
double quiz3;
double quiz4;
int total = 0;
double choice;
ofstream outFile;
double numStud=1;
cout << "Enter student ID number, Quiz 1 Grade, Quiz 2 Grade , Quiz 3 Grade, Quiz 4 Grade" << endl;
outFile.open("StudentGrades.txt");
cout << "How many students would you like to enter?" << endl;
cin >> numStud;
for (int x = 0; x < numStud; x++)
{
cout << "Enter student ID: ";
cin >> studentID;
cout << "Enter quiz grade 1: ";
cin >> quiz1;
//cout << quiz1;
cout << "Enter quiz grade 2: ";
cin >> quiz2;
//cout << quiz2;
cout << "Enter quiz grade 3: ";
cin >> quiz3;
//cout << quiz3;
cout << "Enter quiz grade 4: ";
cin >> quiz4;
//cout << quiz4;
cout << endl;
//outFile.open("StudentGrades.txt");
if (outFile.is_open())
{
cout << "inside if/else outFile" << endl;
//outFile << "File successfully open";
outFile << studentID << " " << quiz1 << " " << quiz2 << " " << quiz3 << " " << quiz4 << endl;
}
else
{
cout << "Error opening file";
}
outFile.close();
/*cout << "Enter 0 for no more students. Enter 1 for more students." << endl;
cin >> choice;
if (choice == 1)
continue;
if (choice == 0)
{
outFile.close();
break;
}*/
}
ifstream inFile;
inFile.open("StudentGrades.txt");
int sTotal;
int total[numStud];
while (inFile >> studentID >> quiz1 >> quiz2 >> quiz3 >> quiz4)
{
//cout << studentID << " " << quiz1 << " " << quiz2 << " " << quiz3 << " " << quiz4 << endl;
total = (quiz1 + quiz2 + quiz3 + quiz4);
sTotal = total[numStud];
double avg = total / 4;
}
system("pause");
return 0;
}
int total[numStud]; is a variable length array and is not standard in C++. If you need an array and you don't know what the size will be then you should use a std::vector. A vector can be used almost exactly as an array can. For example you could would become:
int total;
std::vector<int> studentTotal;
while (inFile >> studentID >> quiz1 >> quiz2 >> quiz3 >> quiz4)
{
//cout << studentID << " " << quiz1 << " " << quiz2 << " " << quiz3 << " " << quiz4 << endl;
studentTotal.push_back(quiz1 + quiz2 + quiz3 + quiz4); // insert into the vector at the end
total += studentTotal.back(); // get last inserted element
}