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. 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"
. It seems you meant to extract into the variable 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.
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 << a << ' ';
and
cout << "\nNos of counts " << b;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.