I am trying to loop this program for a CS class of mine. Everytime I try to do a do,while loop in the main part, it doesn't work. This isnt exactly a problem with Dev-C++, but i know there is someone here who can help. Below is a copy of the program:
string Name;
cout << "Enter name in Last, First format: ";
getline(cin, Name);
cout << Name << endl;
int comma = Name.find(",");
string Last = Name.substr(0, comma);
string First = Name.substr(comma + 2, 999);
cout << First << " " << Last << endl;
}
//**********************************************************
int main()
{
WriteFirstLast();
system("PAUSE");
return 0;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to loop this program for a CS class of mine. Everytime I try to do a do,while loop in the main part, it doesn't work. This isnt exactly a problem with Dev-C++, but i know there is someone here who can help. Below is a copy of the program:
#include <iostream.h>
#include <stdlib.h>
#include <string>
//**********************************************************
void WriteFirstLast(){
string Name;
cout << "Enter name in Last, First format: ";
getline(cin, Name);
cout << Name << endl;
int comma = Name.find(",");
string Last = Name.substr(0, comma);
string First = Name.substr(comma + 2, 999);
cout << First << " " << Last << endl;
}
//**********************************************************
int main()
{
WriteFirstLast();
system("PAUSE");
return 0;
}
// Start of Prog
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
//**********************************************************
bool WriteFirstLast()
{
string Name;
cout << "Enter name in Last, First format: ";
getline(cin, Name);
if (Name == "") // CLS If nothing is entered
return false; // CLS Quit loop
cout << Name << endl;
int comma = Name.find(",");
string Last = Name.substr(0, comma);
string First = Name.substr(comma + 2, 999);
cout << First << " " << Last << endl;
return true; // CLS Everything A-ok
}
//**********************************************************
int main()
{
bool success = true;
while(success) // CLS Loop condition based on return val of WriteFirstLast()
{
success = WriteFirstLast();
}
system("PAUSE");
return 0;
}
// End of Prog
By not entering anything and just hitting 'enter' the loop will exit. I believe that this is what you were looking for.
Curtis