GP32 Help! Making My Program


Raydiosis

Still Fresh
Joined
Mar 18, 2004
Messages
20
I started learning C++ this morning using various tutorials, I want to make something for the gp32 (eventually)
Anyway, this is the code im working on at the moment:
Code:
//basic input/output file thing...
#include <iostream.h>
//main code
int main ()
//start main code block
{
	//welcome messages
	cout << "Welcome to my C++ calculator.\n";
  	cout << "I hope it works for you ^_^.\n";
	cout << "Choose a function (add, dov, mul, sub).\n";
	char a[3];
	cin >> a;
	cout << "You chose calculator function " << a << ".\n";
	cout << "Ok, now which number do you want to " << a << "?.\n";
	int b;
	cin >> b;
	cout << "Right, now what do you want to " << a << " with " << b << "?.\n";
	int c;
	cin >> c;
	cout << "I have used " << b << " and " << c << " and used the " << a << " function, here is the resulting integer:\n";
	//IF commands to determine what function you used, and the resulting integer

	//end main code block	
}

I need to know how to do an IF command that asks whether
a = div
I tried using the method I use for say 'a = 5', but it doesnt work!
Should I be using a different variable type? please help
 
I really think you should learn C prior to C++, as someone mentioned earlier on the dev boards.
Regarding your problem, you could either let the user enter numbers instead of add/div/sub/mul (like, "1- add, 2- sub...") and check for them ( if(a==1) result=c+b; ) or check for the first letter ( I think it was like if(a[0]=='a') result=c+b; and so on).
 
Thanks, I went for the detecting the first letter option :) worked brilliant

Ive got enough knowledge now to make a simple text adventure/text rpg game with save/load :D
 
I need to know how to do an IF command that asks whether
a = div
I tried using the method I use for say 'a = 5', but it doesnt work!
Should I be using a different variable type? please help
For reference:

To compare strings, you need to use a function:
strcmp(a, "div"), will equal 0 if they are equal, a positive if "a" is after div alphabetically or negative if "a" is before div alphabetically.

You will need #include <string.h> at the top of your code to use strcmp as well.
strcmp stands for STRingCoMPare, if you were wondering.

But the way suggested above is a better way.
 
Last edited by a moderator:
Back
Top