Nov 4, 2013 at 4:06am UTC
I'm new at this too, but this is one way of doing it:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string playerName;
int test;
cout << "Enter your name: ";
cin >> playerName;
cout << "Hello, "<<playerName<<".\n";
cout << "Type [1] to test money.\n";
cin >> test;
if (test = 1)
{cout << "You gained $2,500.\n";}
return 0;
}
Last edited on Nov 4, 2013 at 4:06am UTC
Nov 4, 2013 at 4:19am UTC
Try something like
1 2 3 4 5 6 7 8
char option;
cout << "Type [A] to test money." << endl;
cin >> option;
if ( option == 'a' || option == 'A' ) //if you entered a or A
{
cout << "You gained $2,500." << endl;
}
You may also want to check out sub functions and classes/structures.
Here's a quick demo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include <iostream>
#include <string>
//std:: is scoping to the std namespace.
struct Player
{
std::string name;
int money;
};
int main()
{
Player p1{ "Giblit" , 2500 } , p2;
std::cout << "Your name is " << p1.name << std::endl;
std::cout << "You have $" << p1.money << " dollars." << std::endl;
std::cout << "Enter player 2 name: " ;
std::cin >> p2.name; //getline if you want full name
std::cout << "Enter your money " << p2.name << ": " ;
std::cin >> p2.money;
std::cout << "Player 2 name: " << p2.name << std::endl;
std::cout << p2.name << " has $" << p2.money << " dollars." << std::endl;
return ( 0 );
}
*had a missing semi-colon.
Last edited on Nov 4, 2013 at 4:20am UTC
Nov 4, 2013 at 9:43pm UTC
Thanks to both of you!
@giblit
I was actually going to make a "Player" class today, but I just wanted to do the "Test money" thing to learn how to do player input.
Last edited on Nov 4, 2013 at 9:52pm UTC
Nov 4, 2013 at 11:55pm UTC
I'm new to this forum guys.. how can I create my own topic
Nov 5, 2013 at 12:23am UTC
at the top there is a button called "new topic" press it.