News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

char in C::B leading to a skip in else

Started by wrightjh, February 28, 2011, 11:56:04 PM

Previous topic - Next topic

wrightjh

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;

stahta01

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++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Jenna

#2
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.