H
Horn
I am having trouble comparing strings. When I run the program and I
type in what I think is the right string, it goes to the else part of
the program. This is for my computer science class in high school so
excuse me if you think it's really easy. If you know what I should do
then please send me a message at (e-mail address removed)
//Britton Horn
#include "stdafx.h"
#include <iostream.h>
#include <stdlib.h>
#ifndef _OOSTRING_H
#define _OOSTRING_H
#include <string.h>
int main()
{
char yourname[25];
char myname[25] = "britton";
int answer;
cout << "What is your name?\n";
cin.get(yourname, 25);
if (yourname == myname)
{
cout << "What is 2 + 2?\n";
cin >> answer;
cout << "Correct!\n";
}
else
{
cout << "What is 2 + 2?\n";
cin >> answer;
if (answer == 4)
{
cout << "I'm sorry. The answer is 22.\n";
}
if (answer != 4)
{
cout << "I'm sorry. The answer is 4.\n";
}
}
return 0;
#endif
}
type in what I think is the right string, it goes to the else part of
the program. This is for my computer science class in high school so
excuse me if you think it's really easy. If you know what I should do
then please send me a message at (e-mail address removed)
//Britton Horn
#include "stdafx.h"
#include <iostream.h>
#include <stdlib.h>
#ifndef _OOSTRING_H
#define _OOSTRING_H
#include <string.h>
int main()
{
char yourname[25];
char myname[25] = "britton";
int answer;
cout << "What is your name?\n";
cin.get(yourname, 25);
if (yourname == myname)
{
cout << "What is 2 + 2?\n";
cin >> answer;
cout << "Correct!\n";
}
else
{
cout << "What is 2 + 2?\n";
cin >> answer;
if (answer == 4)
{
cout << "I'm sorry. The answer is 22.\n";
}
if (answer != 4)
{
cout << "I'm sorry. The answer is 4.\n";
}
}
return 0;
#endif
}