This is some code which is supposed to program a simple iPhone application which generates a random number, the user must guess the correct number and the program will give it the appropriate feedback. The main code itself seems to compile succesfully in C++ (we changed the file extension to main.mm because of this) however, we only started working on the GUI after we had finished the main code.
The only error we have received is the one indicated in red text regarding the randomly generated number in the ViewController.h file. Any suggestions as to how to solve this problem? Is there anything else which would prohibit the code from functioning seamlessy together in a working iPhone application?
We are honestly beginners and would appreciate any help whatsoever.
main.mm:
#import <UIKit/UIKit.h>
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
//Seed random number generator
srand(time(0));
//Creates the random number between 1 and 10
int theNumber = rand() % 10 + 1;
int guess;
//Guessing loop
int tries;
while (guess != theNumber)
{
cout<<"Please guess the number!: ";
cin>>guess;
++tries;
if (guess > theNumber)
cout<<"Too high,Guess again:"<< endl << endl;
if (guess < theNumber)
cout << "Too low,Guess again: "<< endl << endl;
}
cout << endl << "Congrats!! You got it" //<<tries<< "guesses."
<< endl;
return 0;
}
RandomnumberViewController.m:
#import "Randomnumber6ViewController.h"
@implementation Randomnumber6ViewController
@synthesize txtNumber,lblPleaseguess;
-(IBAction) updateText

id) sender {
NSString *text;
if([srand(time(0)] == int guess) {
text = @"Congrats!! You got it";
}
else
{
if (guess > theNumber) text = [[NSString alloc] initWithFormat:@"Too high,Guess again:"
if (guess < theNumber) text = [[NSString alloc] initWithFormat:@"Too low,Guess again:"
}
lblPleaseguess.text = text;
[text release];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
}
@end
RandomnumberViewController.h:
#import <UIKit/UIKit.h>
@interface Randomnumber6ViewController : UIViewController {
IBOutlet UITextField *txtNumber;
IBOutlet UILabel *lblPleaseguess;
}
@property(nonatomic,retain) IBOutlet UITextField *txtNumber;
@property(nonatomic,retain) IBOutlet UILabel *lblPleaseguess;
- (IBAction) updateText

id) sender;
@end