There are problems with your code, even though you don't actually ask a question about the mess.
1. the lack of code tags AND double-spacing each line make your code hard to read and comment on. PLEASE learn to use code tags.
http://www.cplusplus.com/articles/jEywvCM9/
(hint: you can edit your post and add the code tags.)
2. you are not initializing the dynamic memory variables, using new or new[].
3. no need to double space each line, it makes your code harder to read and understand. Even with code tags.
4. you are missing a number of semicolons, so what should be separate code lines the compiler treats as a single statement.
5. you are missing at least one closing bracket }.
6. you start to assign a value to a variable, without any value. Or a semicolon to finish the code statement.
It takes a lot of work to get your code into a compilable (and readable) form.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
#include <cstring> // std::strlen : http://www.cplusplus.com/reference/cstring/strlen/
int main()
{
// alway have enough space for the terminating null character '\0'
// and for excessive data entry
const int MAXNAME = 256;
char* name { new char[MAXNAME] };
// loop until exactly 10 characters are entered
do
{
std::cout << "Enter your last name with exactly 10 characters.\n";
std::cout << "If your name has < 10 characters, repeat last letter.\n"
<< "Blanks at the end do not count.\n: ";
std::cin.getline(name, MAXNAME);
std::cout << '\n';
}
while (std::strlen(name) < 10 || std::strlen(name) > 10);
std::cout << "Hi, ";
// output your C string using pointer notation
for (size_t pos = 0; pos < std::strlen(name); pos++)
{
std::cout << *(name + pos);
}
std::cout << "\n\n";
int* one { new int(0) };
int* two { new int(0) };
int* three { new int(0) };
std::cout << "Enter three integer numbers separated by blanks\n: ";
std::cin >> *one >> *two >> *three;
std::cout << '\n';
std::cout << "The three numbers are\n"
<< *one << ' ' << *two << ' ' << *three << '\n';
int result { *one + *two + *three };
std::cout << "The sum of the three values is " << result << '\n';
// it pays to be neat, clean up after yourself
delete[] name;
delete one;
delete two;
delete three;
}
| |
Enter your last name with exactly 10 characters.
If your name has < 10 characters, repeat last letter.
Blanks at the end do not count.
: de Blasio
Enter your last name with exactly 10 characters.
If your name has < 10 characters, repeat last letter.
Blanks at the end do not count.
: my name is a long one
Enter your last name with exactly 10 characters.
If your name has < 10 characters, repeat last letter.
Blanks at the end do not count.
: mylastname
Hi, mylastname
Enter three integer numbers separated by blanks
: 3 4 5
The three numbers are
3 4 5
The sum of the three values is 12 |