Go Back   Gaming Gutter > Non-Gaming > Programming > Source Code


Source Code - Have a source code/project files you want to post? Do so here.

» Site Navigation
» Home
» FAQ
» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Advertisement
» GG Stuff

Follow us on Twitter!

Get the GG toolbar today (for firefox only)
» Recent Threads
Go to first new post If you got a FFQ, what...
11-12-2009 12:22 AM
Last post by BSavage
Today 08:17 AM
28 Replies, 350 Views
Go to first new post I Need a Favor!!! My...
Today 08:14 AM
by Charger
Last post by Salix
Today 08:16 AM
1 Replies, 2 Views
Go to first new post 1.4billion :o
11-16-2009 12:43 PM
by tWi
Last post by Oops
Today 08:14 AM
16 Replies, 324 Views
Go to first new post ~ The Official Hash...
11-06-2009 11:56 AM
by mehike
Last post by shadyangelz
Today 08:05 AM
154 Replies, 2,441 Views
Go to first new post [PHP] MD5 List Cracker
11-19-2009 05:00 PM
by tWi
Last post by tWi
Today 08:04 AM
13 Replies, 198 Views
Reply
 
LinkBack Thread Tools Display Modes

 Cout / cin / if C++ help??
Old 08-03-2009, 10:09 AM   #1 (permalink)
Junior Member

Male MYST is offline
 
MYST's Avatar
 
Join Date: Aug 2009
Location: London
Age: 20
Posts: 2
GPoints: 402
iTrader: 0 / 0%
MYST Is a New Face in Town
Rep Power: 0
Cout / cin / if C++ help??

Hi all,

Im new to this forum, so first up, greetings!

Secondly, ive only recently got into C++ and need a bit of help.

I'm wondering how you can get your console program to recognise variable char's.

For example -

Code:
#include <iostream>

int main()

{
	using namespace std;
	int age;
	char name [5];
	
		cout << "Hi, whats your name? \n" ;
	
	cin >> name ;

		cout << " So " << name  << " how old are you? \n";

	cin >> age;

		if (age > 20)

cout << " Great!\n";

else 

cout << " too bad your too young \n ";

		return 0;

}
You can see that the if statement recognises int variables and can decipher whether or not the input from cin is greater than 20.

Is there a way you can use an if statement to, for example decipher between the word yes or no. Or distinguish between 2 names?

It's being written in Microsoft Visual C++ 2008 if that helps

Thanks in advance!
  Reply With Quote

 
Old 08-03-2009, 10:12 AM   #2 (permalink)
C++
Full Member

Undisclosed C++ is offline
 
Join Date: Jul 2009
Posts: 62
GPoints: 1,263
iTrader: 2 / 100%
C++ Is Recognizable
Rep Power: 1
Did you mean something like this?

Code:
#include <iostream>

int main()

{
	using namespace std;
	int age;
	char name [5];
	
		cout << "Hi, whats your name? \n" ;
	
	cin >> name ;
        
	if (name == "tony")
	 cout << " So " << name  << " how old are you? \n";

	else 
			cout << "Tony is the only acceptable name!";

	cin >> age;

		if (age > 20 )

cout << " Great!\n";

else 

cout << " too bad your too young \n ";

		return 0;

}
__________________


Last edited by C++; 08-03-2009 at 10:29 AM..
  Reply With Quote

 
Old 08-03-2009, 10:36 AM   #3 (permalink)
Junior Member

Male MYST is offline
 
MYST's Avatar
 
Join Date: Aug 2009
Location: London
Age: 20
Posts: 2
GPoints: 402
iTrader: 0 / 0%
MYST Is a New Face in Town
Rep Power: 0
Yeah, i did try that and when i compiled it, it didn't work. And i just compiled your code and the only response i could get, is Tony is the only acceptable name.

Even when putting Tony in as the name....
  Reply With Quote

 
Old 08-03-2009, 02:57 PM   #4 (permalink)
C++
Full Member

Undisclosed C++ is offline
 
Join Date: Jul 2009
Posts: 62
GPoints: 1,263
iTrader: 2 / 100%
C++ Is Recognizable
Rep Power: 1
Quote:
Originally Posted by MYST View Post
Yeah, i did try that and when i compiled it, it didn't work. And i just compiled your code and the only response i could get, is Tony is the only acceptable name.

Even when putting Tony in as the name....

Fixed it

Code:
#include "stdafx.h"
#include <iostream>
#include <string>




int main()

{
	using namespace std;
	int age;
	string name ;
	
		cout << "Hi, whats your name? \n" ;
	
	cin >> name ;
    
	if (name == "tony")
		cout << " So " << name  << " how old are you? \n";
	else
		cout << "wrong name";
	
	cin >> age;
 
		if (age > 20)

cout << " Great!\n";

else 

cout << " too bad your too young \n ";

		return 0;

}
__________________


Last edited by C++; 08-03-2009 at 02:58 PM.. Reason: Automerged Doublepost
  Reply With Quote
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Powered by vBadvanced CMPS v3.1.0

All times are GMT -7. The time now is 08:26 AM.


vBulletin skin developed by: eXtremepixels
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The contents of this webpage are copyright © 2006-2008 GamingGutter.com. All Rights Reserved.

Page generated in 0.25523305 seconds (100.00% PHP - 0% MySQL) with 21 queries