hi all. i've written a program in C++ using the exact instruction my teacher has given me, and for some reason, it does not work. could someone tell me what might be wrong? i have the entire program basically finished, i think:
#include<iostream>
#include<string>
#include<ctime>
#include<stdlib.h>
using namespace std;
int WriteFirstLast(string &name)
{
int first;
int last;
int length;
int comma;
length=name.length();
comma=name.find(",");
last=name.substr(0, comma-1);
first=name.substr((comma+1), (last-1));
return first, last, length, comma;
}
int main()
{
srand((unsigned)time(0));
int first;
int last;
int length;
int comma;
string name;
cout<<"Enter name (last,first): "; cin>>name;
first=WriteFirstLast(name);
last=WriteFirstLast(name);
cout<<"Name: "<<first<<" "<<last;
system("pause");
return(0);
}
Question
Timmah339
hi all. i've written a program in C++ using the exact instruction my teacher has given me, and for some reason, it does not work. could someone tell me what might be wrong? i have the entire program basically finished, i think:
#include<iostream> #include<string> #include<ctime> #include<stdlib.h> using namespace std; int WriteFirstLast(string &name) { int first; int last; int length; int comma; length=name.length(); comma=name.find(","); last=name.substr(0, comma-1); first=name.substr((comma+1), (last-1)); return first, last, length, comma; } int main() { srand((unsigned)time(0)); int first; int last; int length; int comma; string name; cout<<"Enter name (last,first): "; cin>>name; first=WriteFirstLast(name); last=WriteFirstLast(name); cout<<"Name: "<<first<<" "<<last; system("pause"); return(0); }Link to comment
Share on other sites
11 answers to this question
Recommended Posts