Need modifiable l-value

Hey guys I'm trying to make a program for myself and this is what I have so far
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
28
29
#include <iostream>
#include <string>
#include <new>
using namespace std;
#define K 1000;
#define k 1000;
#define M 1000000;
#define m 1000000;
int main()
{
	string name;
	char cash_pile[10];
	string answer;
	char bet[10];
	cout<<"hi this is a calculator to calculate dicing percentages"<<endl;
	cout<<"what is your  name?"<<endl;
	cin>>name;
	cout<<"how big is your cash pile right now?"<<endl;
	cin>>cash_pile;
	cout<<"your name is "<<name<<" and you currently have "<<cash_pile<<" GP is that correct?"<<endl;
	cin>>answer;
	if (answer=="yes" || answer=="y" || answer=="Y" || answer=="Yes"|| answer=="yep" || answer=="Yep" || answer=="Yea" || answer=="yea")
	{
		cout<<"okay how much are you going to bet?"<<endl;
		cin>>bet;
		cash_pile-bet=result; //right here it says need modifiable l value, I know the problem is that they are static arrays I just cant think of a way around it.
	}
	system("pause");
}

Thanks!
the 'get' operator = takes the calculated value on the right and puts it in the container on the left.

1
2
int a, b, c;
a - b = c; 
is invalid because you are sticking a container's value on the right into a calculated value on the left.

YOu need to do this:
c = a - b
It didnt help I get the same error
Are cash_pile and bet symbols or numbers?
Replace
1
2
3
char cash_pile[10];
string answer;
char bet[10];


With
1
2
3
int cash_pile;
string answer;
int bet;
Last edited on
also, result is undefined. define it as an int.
Last edited on
Yea thats the problem though, the reason i had it as an array is because I want to be able to input K and M to represent thousand and million. thats why int wouldnt work. Any way around this?
Wait, int doesn't go all the way to a million for you?

What about long?

(or am I misunderstanding your problem?)
haha no int goes to a million but I want the user to be able to input lets say 10M. and the program will recognize that as 10000000, that is what I have yet to understand.
Okay, so in this case, you'll read cash_pile as a string or char*, however you will then need to parse the string/char* and manipulate it until you get a numeric value of 10000000. You are missing that step. You can't do math operations on a string or char*.
could you give me an example im kind of confused
Parsing gets complicated. Here's a function that might do what you are expecting:

Then add this above your main:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int parse (string in)
{
	int output = 0;
	for (int i = 0; i < in.size(); i++)
	{
		if (in[i] >= '0' || in[i] <= '9')
		{
			output *= 10;
			output += in[i] - '0';
		}
		if (in[i] == 'M') 
		{
			output *= 1000000;
		}
	}

	return output;
}


Then use:
int result = parse(cash_pile) - parse(bet);
Last edited on
Yeah, parsing can get kinda tricky.

This works, for the most part (as long as you trust your users not to enter anything funky):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int parse(const string& input)
{
	istringstream convert(input);
	int coeff;
	convert >> coeff;
	if (convert.eof())
		return coeff;
	
	char mk = convert.get();
	if (mk == 'M')
		return coeff * 1000000;
	else if (mk == 'K')
		return coeff * 1000;
	else
		return coeff;
}


Just put #include <sstream> in your code.
Where should I learn how to write the things that aren't in this sites c++ tutorial because I know parsing isn't I have never even heard of it hahaha.
Topic archived. No new replies allowed.