Author Topic: char in C::B leading to a skip in else  (Read 5436 times)

wrightjh

  • Guest
char in C::B leading to a skip in else
« on: February 28, 2011, 11:56:04 pm »
I'm new to using C::B and used to code using Visual Basic 6

I've been searching for ways to get my code to use the "else" but every time is goes straight to the if even if I don't type "gregg."
Could this be due to the way that I am writing char? I tried "char name[15];" but I still does the same thing. Is this a problem with the way I am writing code or because C::B is different? If you have any Ideas they would be very helpful.

#include <iostream>
#include <string>
using namespace std;
int main()
{
    char[15] name;
    cout<< "What is your name? ";
    cin>> name;
    if (name == "Gregg" or "gregg")
    cout<< "Screw You";

    else
    cout<< "Hi " <<name<<  " How are you?";
    return 0;

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7666
    • My Best Post
Re: char in C::B leading to a skip in else
« Reply #1 on: March 01, 2011, 02:17:50 am »
Read about strcmp and post your programming questions an another site!!!
Like http://cboard.cprogramming.com/c-programming/

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Re: char in C::B leading to a skip in else
« Reply #2 on: March 01, 2011, 06:53:46 am »
As Tim wrote this is a general programming question and not C::B related.
This is a violation of our forum rules !

Topic locked !!

By the way:
you should use C++syntax in your C++-programs, not VB-syntax or a mix of both as you did.
« Last Edit: March 01, 2011, 06:56:14 am by jens »