'string' does not name a type

Hi... I am trying to do a sketch for my uno that receive input from mega and then transmit message to my phone..Im kinda confuse on the declaration of the string and im keep getting error like this( 'string' does not name a type")
Here are my code

#include <SoftwareSerial.h>
#include <String.h>



SoftwareSerial gsmSerial(10, 11); // RX, TX
int val01=0;
int val02=0;
string x;
string myString[1] = "Water is Acidic..Neutralizing.";
string myString[2] = "Water is Alkalic..Changing water";


void setup() {
gsmSerial.begin(9600);  //Connect to gsm
  Serial.begin(9600);    //Connect to computer 
  delay(500);
  pinMode(A1,INPUT); //input from mega for ACID
  pinMode(A2,INPUT); //input from mega for Alkali
  


}

void loop() {

val01=analogRead(A1);
val02=analogRead(A2);
Serial.begin(19200);
Serial.println(val01);
delay(500);
if (val01>200)
{
string x = myString[1]
  sendTextMessage()
}
else (val02>200)
{
string x=myString[2]
  sendTextmessage()
}
void sendTextMessage()
{
  gsmSerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  gsmSerial.println("AT + CMGS = \"+60195921xxx\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  gsmSerial.println(x);//the content of the message
  delay(100);
  gsmSerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
}

}

That kind of string needs a capital S. I wouldn't recommend using them but at least "String" will get rid of the error message.

Pete

Both C and C++ are case sensitive so it should be String. Even with that correction the code does not seem to make a lot of sense. Also, the use of the String class is very likely to give you memory problems.

else (val02>200)Is there an if missing in this line ?

Save yourself some trouble (now and later) and don't use String. Just use a char array, aka "C string", not the String object defined by String.h.

#include <SoftwareSerial.h>

SoftwareSerial gsmSerial(10, 11); // RX, TX
int val01=0;
int val02=0;

void setup() {
gsmSerial.begin(9600);  //Connect to gsm
  Serial.begin(9600);    //Connect to computer 
  delay(500);
  pinMode(A1,INPUT); //input from mega for ACID
  pinMode(A2,INPUT); //input from mega for Alkali
}

void loop() {

val01=analogRead(A1);
val02=analogRead(A2);
Serial.println(val01);
delay(500);
if (val01>200)
{
  sendTextMessage( "Water is Acidic..Neutralizing." );
}
else if (val02>200)
{
  sendTextMessage( "Water is Alkalic..Changing water" );
}
}


void sendTextMessage( const char *msg )
{
  gsmSerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  gsmSerial.println("AT + CMGS = \"+60195921xxx\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  gsmSerial.println( msg );//the content of the message
  delay(100);
  gsmSerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
}

You had a curly brace in the wrong place, spelled sendTextMessage wrong, and tried to use "else (test)" instead of "else if (test)". The "else" clause does not require a test, because it's what you should do if the "if (test) is false.

And srsly, get your code formatted nicely. Just press ctrl-T in the IDE editor!

Cheers,
/dev

Wow thanks a lot everyone.... Im sorry everyone for the inconveniences, i was really new in this kind of things but its great to be able to learn..well thanks again everyone especially to you /dev ..really great help :slight_smile: