#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <windows.h>
usingnamespace std;
int main () {
char firstname[10];
char lastname[10];
cout << "Enter your first name:\n";
cin >> firstname;
cout << "Your first name is " << firstname;
cout << "\nEnter your last name:\n";
cin >> lastname;
if (firstname == "Sam" || firstname == "sam" || firstname == "SAM")
{
cout << "\n" << lastname << endl;
}
else
cout << "You're not Sam... Get lost n00b!\n";
system("pause");
return 0;
}
and even if I put sam as the firstname it always goes to the you're not sam part... I can't figure out why. I have it working with strings... just need to know if there's anything special I have to do with a character array.
hey, I was trying to make a letter guessing game, but when I use the stricmp command it's is giveing me
error C2664: 'stricmp' : cannot convert parameter 1 from 'char' to 'const char *'
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
int Rand_Num=0,x=0;
char PcLet[27]="abcdefghijklmnopqrstuvwxyz", UsLetGuess[2]={0};
int main()
{
srand(time(NULL));
cout<<"Welcome to my Letter Guessing game!!";
Rand_Num=rand()%((27-1)+1);
cout<<"I have a letter what is it?\n";
cin>>UsLetGuess[x];
if (stricmp(PcLet[Rand_Num],UsLetGuess)==0)
cout<<"Correct!!";
else
cout<<"Incorrect";
cout<<endl;
system("pause");
return 0;
}
can any of you here help me with this problem? thanks.
Thanks that seems to work, But I don't entirely Understand why it's not a char sequence? (Sorry I am kinda new to this, I did it in high school, put it down a little too long and now I need to refresh my memory of all this coding) thanks for the help.
char singleChar = 'c'; // this is a single character with value 'c'
char charArray[] = "abcde"; //This is a char sequence values: 'a', 'b', 'c', 'd', 'e', '\0'
singleChar = charArray[3]; // singleChar is assigned to the value of the (3+1)th character of charArray 'd'
A character sequence is defined by a pointer to the first character of the sequence until the character '\0' is found or the buffer has been completely filled