When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
51 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
again to reclarify I can't use any functions or vectors or like .find. only the approved functions i listed above. I also need the first and last name stored in one variable. i can use two variables for the first and last initial.
current code i have. I am struggling to find a way to get the first and last name initials while following the constraints
what code do you want me to send, the furthest i got with the code is what i replied to above at 3"43pm EST
can u see the code i sent
;compile
look at the list of functions you say you're allowed to use
be sure you understand what each one does
;compile
• type three "backticks" (not quotes/apostrophes, on QWERTY layout, left of 1-key)
• on the same line, type the file extension for that language (c or cpp)
• enter your code on a new line and put another three backticks at the end
```cpp
int main() {
return 0;
}
```
int main() {
return 0;
} ```
#include <iostream>
#include <cmath>
#include <string>
#include <iostream>
using namespace std;
int main()
{
string name;
char firstInitial;
cout << "Enter your first and last name: ";
getline(cin, name);
cout << "Hello " << name;
firstInitial = name.at(0);
return 0;
} ```
;compile
;compile
;compile
ugh
;compile
<source>: In function 'int main()':
<source>:3:5: error: 'string' was not declared in this scope
3 | string name;
| ^~~~~~
<source>:6:5: error: 'cin' was not declared in this scope
6 | cin.get();
| ^~~
<source>:7:5: error: 'cout' was not declared in this scope
7 | cout << "Enter your first and last name: ";
| ^~~~
<source>:9:18: error: 'name' was not declared in this scope
9 | getline(cin, name);
| ^~~~
<source>:9:5: error: 'getline' was not declared in this scope
9 | getline(cin, name);
| ^~~~~~~
Build failed
;compile
<source>: In function 'int main()':
<source>:3:5: error: 'string' was not declared in this scope
3 | string name;
| ^~~~~~
<source>:6:5: error: 'cin' was not declared in this scope
6 | cin.get();
| ^~~
<source>:7:5: error: 'cout' was not declared in this scope
7 | cout << "Enter your first and last name: ";
| ^~~~
<source>:9:18: error: 'name' was not declared in this scope
9 | getline(cin, name);
| ^~~~
<source>:9:5: error: 'getline' was not declared in this scope
9 | getline(cin, name);
| ^~~~~~~
Build failed
;compile
<source>: In function 'int main()':
<source>:3:5: error: 'string' was not declared in this scope
3 | string name;
| ^~~~~~
<source>:6:5: error: 'cout' was not declared in this scope
6 | cout << "Enter your first and last name: ";
| ^~~~
<source>:8:13: error: 'cin' was not declared in this scope
8 | getline(cin, name);
| ^~~
<source>:8:18: error: 'name' was not declared in this scope
8 | getline(cin, name);
| ^~~~
<source>:8:5: error: 'getline' was not declared in this scope
8 | getline(cin, name);
| ^~~~~~~
Build failed
you didn't put all your code in the block
you can see as much because of the colors
this code is running fine with my compiler
I say again
.
;compile
Enter your first and last name:
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 1) >= this->size() (which is 0)
;compile
Enter your first and last name:
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 1) >= this->size() (which is 0)
I think its working but because i am having the user input a value its not running correctly all the way?
oh i left that in there when i was experimenting
;compile
Enter your first and last name:
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)