The function within case 2 does not work for some reason. The expected output says that the parameter is undefined but when I define the parameter it then says it can only be an integer but when I replace the string with an int the on with the variable the debugger still hands out an error saying that "C++ does not support default Int." I keep changing the variable to suit the needs of the debugging but the program will still not run.
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <fstream>
#include <time.h>
#include <stdio.h>
#include <Windows.h>//Secret to play music: Go to project file properties, go to linker and find input, in output write this Winmm.lib and press okay and done.
#include <mmsystem.h>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <deque>
void email(string emailbackup);
using std::cout;
using std::cin;
using namespace std;
int main()
{
int x;
std::cout << "What would you like to do?" << std::endl;
std::cout << "1)Would you like to see the archive?" << std::endl;
std::cout << "2)Would you like to register student information?" << std::endl;
std::cout << "3)Would you like to find a student within the registry?" << std::endl;
std::cout << "4)Delete all student information?" << std::endl;
std::cout << "5)Exit Program?" << std::endl;
std::cin >> x;
switch (x)
{
case 1:
break;
case 2:
email(emailbackup);//This is where the error is located within int main.//
//emailbackup is the parameter I am describing within int main()//
break;
case 3:
break;
case 4:
break;
case 5:
break;
}
}
void email(string emailbackup)
{
string emailbackup;
int studentID = 0;
std::string let("abcdefghijklmnopqrstuvwxyz");
int numbers = (1, 3, 0);
std::string str;
std::string name;
std::string studID;
std::string studID2;
string email;
string studFinal;
std::stringstream concatenate;
std::stringstream concatenatetwo;
int amountofStudents;
std::cout << "How many student archives would you like to enter?" << std::endl;
std::cin >> amountofStudents;
amountofStudents + 1;
for (int i = 0; i < amountofStudents; i++)
{
cout << "Please enter your name.." << std::endl;
std::cin >> name;
while (std::string::npos != name.find_first_of("0123456789"))
{
cout << "You must have letter within user input." << std::endl;
cout << "Please enter your name." << std::endl;
std::cin >> name;
}
//I need to check to see if the first 3 numbers are correct?
//The student ID must be at least 6 digits, and the first 3 numbers must be 130.
cout << "Please enter Your student I.D." << std::endl;
std::cin >> studID;
stringstream(studID) >> studentID;
while (/*std::string::npos != studID.find_first_of("130") */ studentID != 130 /*&& studID.length() <= 6*/)
{
stringstream(studentID) >> studID;
cout << "You must enter 130 as the first 3 digits" << std::endl;
std::cin >> studID;
stringstream(studID) >> studentID;
}
//==============
cout << "Please enter the second part of the student I.D. " << studentID << "-" << std::endl;
std::cin >> studID2;
while (/*std::string::npos != studID.find_first_of("130") */ studID2.length() < 3 || studID2.length() > 3)
{
//stringstream(studentID) >> studID;
cout << "Add 3 more digits." << std::endl;
std::cin >> studID2;
}
concatenate << studentID << "-" << studID2 << endl;
studFinal = concatenate.str();
/*while (studID.length() != 6)
{
cout << "You must enter 130 as the first 3 digits and you must have 6 digits." << std::endl;
std::cin >> studID;
}*/
cout << "Please enter your email.." << endl;
cin >> email;
while (/*string::npos != email.find_first_not_of("@atlanticu.edu")*/ email == emailbackup || email.empty())
{
cout << "Please enter your email..." << endl;
cin >> email;
}
concatenatetwo << email << "@atlanticu.edu" << endl;
email = concatenatetwo.str();
emailbackup = email;
cout << "Your email is.. " << email << endl;
system("pause");
}
}
I just need to know how to fix the function parameter, so that I can execute the program on point.
Think about your function signature.
void email(string emailbackup);
Do you actually want the caller to pass a string to the function email()
?
Because you then define emailbackup inside the function again.
You want something like this probably...
...
case 2:
const string backup = "backup@email";
email(backup);
break;
...
void email(string emailbackup)
{
// string emailbackup; // delete this line
...
}
Also, remove using namespace std;
and be consistent with your namespace usage. Why add using namespace cout, cin
etc if you are calling them with the namespace explicitly ie std::cin, std::cout.
Either add using namespace std::cout
and use cout
rather than std::cout
or vice versa. Don't mix it up. Same with std::string
and string
. Makes it look like you defined your own string...
Just one last thing, for the sake of readability I would suggest breaking this email function into smaller functions. For instance:
void email(string emailbackup)
{
...
int studentID = getStudentID();
string studentEmail = getStudentEmail();
...
}
int getStudentID()
{
int studentID;
cout << "Please enter Your student I.D." << std::endl;
std::cin >> studID;
stringstream(studID) >> studentID;
while (/*std::string::npos != studID.find_first_of("130") */ studentID != 130 /*&& studID.length() <= 6*/)
{
stringstream(studentID) >> studID;
cout << "You must enter 130 as the first 3 digits" << std::endl;
std::cin >> studID;
stringstream(studID) >> studentID;
}
return studentID;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.