[英]Allow user to input first and last name; display full name back to user (first + last)
I know this is something really simple but I can't figure out what I'm missing or doing wrong.我知道这很简单,但我无法弄清楚我错过了什么或做错了什么。 I think it might be something with the char variables.我认为这可能与 char 变量有关。 This is what I have so far:这是我到目前为止:
#include<stdio.h>
#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
char fname[20],lname[20];
cout<<"Please enter your First Name:";
cin>>"fname";
cout<<"Please enter your Last Name:";
cin>>"lname";
cout<<"Your full name is:"<<fname<<lname<<endl;
int a,b = 0;
for(a=0;a<=50;a++)
{
if(a%3!=0&&a%4!=0&&a%5!=0)
{
printf(" %d",a);
b++;
}
}
printf("\nNos of counts%d",b);
}
cin>>"fname";
You are trying to extract into the string literal "fname"
.您正在尝试提取到字符串文字"fname"
。 It seems you meant to extract into the variable fname
:看来您打算提取到变量fname
:
cin>>fname;
Just going to make a couple suggestions since Joseph answered the question.自从约瑟夫回答了这个问题后,我只想提出一些建议。 Add a space between first and last name so it's not printing there name as one word.在名字和姓氏之间添加一个空格,这样它就不会将名字打印为一个词。
cout <<"Your full name is: "<< fname << ' ' << lname << endl;
when declaring b to 0, you didn't assign a to anything.将 b 声明为 0 时,您没有将 a 分配给任何东西。
int a = 0, b = 0;
and cout is much more powerful than printf, you shouldn't use C syntax in C++ unless there is no other option.并且 cout 比 printf 强大得多,除非没有其他选择,否则不应在 C++ 中使用 C 语法。
cout << a << ' ';
and和
cout << "\nNos of counts " << b;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.