LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-14-2019, 12:00 AM   #1
twirl
Member
 
Registered: Aug 2005
Posts: 166

Rep: Reputation: 15
Question Help with small C++ Sublime program errors


Hi,

I suffer with memory loss and I need help remembering how to fix the following errors please in linux mint 19 cinnamon :-

Quote:
gcc random.cpp
random.cpp:75:22: warning: missing terminating ' character
break'
^
random.cpp:75:22: error: missing terminating ' character
random.cpp:7:5: error: expected initializer before ‘int’
int a;
^~~
random.cpp:9:5: error: expected unqualified-id before ‘do’
do{
^~
random.cpp:14:5: error: expected unqualified-id before ‘switch’
switch(a)
^~~~~~
random.cpp:97:2: error: expected unqualified-id before ‘while’
}while{true);}
^~~~~
Code:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main()                                  //start of program
    int a;
    string program_name;
    do{
    a = (rand()%37);                        //assign output messages from number 0 to 37
    getline(cin, program_name);            //get keyboard input
    if(program_name == " Welcome to Sublime 1.0");
    continue;}
    switch(a)
    {                                          // display random text message on screen
             case 0;
                cout << "me and my family are surrounded by the universal most highest unbreakable protect from all types and kinds at all times";
                break;
             case 1;
                cout << "me and my family are surrounded by a forceshield at all times and anyone who tries to cause harm will become very ill instantly";
                break;
             case 2;
                cout << "i have the universe most powerful supernatural abilities at all times";
                break;
             case 3;
                cout << "i can control the weather of any type all times";
                break;
             case 4;
                cout << "i am insivible at all times";
                break;
             case 5;
                cout << "all evil against me and my family has now been completely removed ";
                break;
             case 6;
                 cout << "all magic used against me and my family is now broken and returned to senders one millions time fold";
                break;
             case 7;
                 cout << "i now have a beauitful wife with great personality and is loyal and faithul and trust worthy only to me and has good sense of humour and is kind and sensitive";
                break;
             case 8;
                 cout << "my child rainbow and other children are now born";
                break;
             case 9;
                 cout << "me and my wife now have as many kids as she wants";
                break;
             case 10;
                 cout << "i am always excellent in everything i do";
                break;
             case 11;
                 cout << "i have an amazing memory and learn and understand everything in an instant in all shapes and forms and types";
                break;
             case 12;
                 cout << "i am always excellent at selling online and offline of any product or service";
                break;
             case 13;
                 cout << "the university of worcester is now suffering the consequences of all the problems it and its students have caused in england";
                break;
             case 14;
                 cout << "all greedy and useless landlords in england have now been removed and repleced with decent caring and understanding ones";
                break;
             case 15;
                 cout << "i am always wealthy and rich and always have unlimited money";
                break;
             case 16;
                 cout << "i am always invisible";
                break;
             case 17;
                 cout << "i always have superpowers of all types and abilities at all times";
                break;
             case 18;
                 cout << "i am the best in the music business of the type of music i make"; 
                break;
             case 19;
                 cout << "i am always surrounded by those who love me only";
                break'
             case 20;
                 cout << "me and my family are surrounded by the universe most highest postive energy and vibrations only at all times";
                break;
             case 21;
                 cout << "i can control all types of weather and make it do whatever i want at all times"; 
                break;
             case 22;
                 cout << "i can see all  hidden and known at all times";
                break;
             case 33;
                 cout << "all those who take the piss out me and my family will end up homeless";
                break;
             case 34;
                 cout << "all hmos are now turned back into lovely family homes with decent families only";
                break;
             case 35;
                 cout << "matt richards who i know off and his friends and family and girlfriends and children are now all banished forever";
                break;
             case 36;
                 cout << "me and my family are surrounded by only true loving entities who help us at all times"; 
                 break
}while{true);}
 
Old 07-14-2019, 03:00 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,781

Rep: Reputation: 1239Reputation: 1239Reputation: 1239Reputation: 1239Reputation: 1239Reputation: 1239Reputation: 1239Reputation: 1239Reputation: 1239
Change int main() to int main() {
break' to break;

Last edited by NevemTeve; 07-14-2019 at 03:02 AM.
 
Old 07-14-2019, 05:49 AM   #3
hazel
Senior Member
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 3,020
Blog Entries: 7

Rep: Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584
You are much less likely to get brace mismatches if you always put braces that are supposed to match underneath each other in the same column. Then a quick test in a syntax-checking editor will show you whether the numerically matching brace (the one that lights up in the editor) is the same as the logically matching one.

That is even more important if you have memory problems and are trying to debug a program some time after writing or editing it.
 
Old 07-14-2019, 03:32 PM   #4
twirl
Member
 
Registered: Aug 2005
Posts: 166

Original Poster
Rep: Reputation: 15
Question

Hi,

I edited it as you said and now I am getting these errors :-

Quote:
gcc sublime.cpp
sublime.cpp: In function ‘int main()’:
sublime.cpp:14:11: error: expected ‘while’ before ‘(’ token
switch(a)
^
sublime.cpp:15:5: error: expected ‘;’ before ‘{’ token
{ // display random text message on screen
^
sublime.cpp:16:14: error: case label ‘0’ not within a switch statement
case 0;
^~~~
sublime.cpp:16:20: error: expected ‘:’ before ‘;’ token
case 0;
^
sublime.cpp:18:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:19:14: error: case label ‘1’ not within a switch statement
case 1;
^~~~
sublime.cpp:19:20: error: expected ‘:’ before ‘;’ token
case 1;
^
sublime.cpp:21:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:22:14: error: case label ‘2’ not within a switch statement
case 2;
^~~~
sublime.cpp:22:20: error: expected ‘:’ before ‘;’ token
case 2;
^
sublime.cpp:24:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:25:14: error: case label ‘3’ not within a switch statement
case 3;
^~~~
sublime.cpp:25:20: error: expected ‘:’ before ‘;’ token
case 3;
^
sublime.cpp:27:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:28:14: error: case label ‘4’ not within a switch statement
case 4;
^~~~
sublime.cpp:28:20: error: expected ‘:’ before ‘;’ token
case 4;
^
sublime.cpp:30:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:31:14: error: case label ‘5’ not within a switch statement
case 5;
^~~~
sublime.cpp:31:20: error: expected ‘:’ before ‘;’ token
case 5;
^
sublime.cpp:33:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:34:14: error: case label ‘6’ not within a switch statement
case 6;
^~~~
sublime.cpp:34:20: error: expected ‘:’ before ‘;’ token
case 6;
^
sublime.cpp:36:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:37:14: error: case label ‘7’ not within a switch statement
case 7;
^~~~
sublime.cpp:37:20: error: expected ‘:’ before ‘;’ token
case 7;
^
sublime.cpp:39:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:40:14: error: case label ‘8’ not within a switch statement
case 8;
^~~~
sublime.cpp:40:20: error: expected ‘:’ before ‘;’ token
case 8;
^
sublime.cpp:42:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:43:14: error: case label ‘9’ not within a switch statement
case 9;
^~~~
sublime.cpp:43:20: error: expected ‘:’ before ‘;’ token
case 9;
^
sublime.cpp:45:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:46:14: error: case label ‘10’ not within a switch statement
case 10;
^~~~
sublime.cpp:46:21: error: expected ‘:’ before ‘;’ token
case 10;
^
sublime.cpp:48:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:49:14: error: case label ‘11’ not within a switch statement
case 11;
^~~~
sublime.cpp:49:21: error: expected ‘:’ before ‘;’ token
case 11;
^
sublime.cpp:51:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:52:14: error: case label ‘12’ not within a switch statement
case 12;
^~~~
sublime.cpp:52:21: error: expected ‘:’ before ‘;’ token
case 12;
^
sublime.cpp:54:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:55:14: error: case label ‘13’ not within a switch statement
case 13;
^~~~
sublime.cpp:55:21: error: expected ‘:’ before ‘;’ token
case 13;
^
sublime.cpp:57:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:58:14: error: case label ‘14’ not within a switch statement
case 14;
^~~~
sublime.cpp:58:21: error: expected ‘:’ before ‘;’ token
case 14;
^
sublime.cpp:60:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:61:14: error: case label ‘15’ not within a switch statement
case 15;
^~~~
sublime.cpp:61:21: error: expected ‘:’ before ‘;’ token
case 15;
^
sublime.cpp:63:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:64:14: error: case label ‘16’ not within a switch statement
case 16;
^~~~
sublime.cpp:64:21: error: expected ‘:’ before ‘;’ token
case 16;
^
sublime.cpp:66:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:67:14: error: case label ‘17’ not within a switch statement
case 17;
^~~~
sublime.cpp:67:21: error: expected ‘:’ before ‘;’ token
case 17;
^
sublime.cpp:69:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:70:14: error: case label ‘18’ not within a switch statement
case 18;
^~~~
sublime.cpp:70:21: error: expected ‘:’ before ‘;’ token
case 18;
^
sublime.cpp:72:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:73:14: error: case label ‘19’ not within a switch statement
case 19;
^~~~
sublime.cpp:73:21: error: expected ‘:’ before ‘;’ token
case 19;
^
sublime.cpp:75:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:76:14: error: case label ‘20’ not within a switch statement
case 20;
^~~~
sublime.cpp:76:21: error: expected ‘:’ before ‘;’ token
case 20;
^
sublime.cpp:78:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:79:14: error: case label ‘21’ not within a switch statement
case 21;
^~~~
sublime.cpp:79:21: error: expected ‘:’ before ‘;’ token
case 21;
^
sublime.cpp:81:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:82:14: error: case label ‘22’ not within a switch statement
case 22;
^~~~
sublime.cpp:82:21: error: expected ‘:’ before ‘;’ token
case 22;
^
sublime.cpp:84:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:85:14: error: case label ‘33’ not within a switch statement
case 33;
^~~~
sublime.cpp:85:21: error: expected ‘:’ before ‘;’ token
case 33;
^
sublime.cpp:87:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:88:14: error: case label ‘34’ not within a switch statement
case 34;
^~~~
sublime.cpp:88:21: error: expected ‘:’ before ‘;’ token
case 34;
^
sublime.cpp:90:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:91:14: error: case label ‘35’ not within a switch statement
case 35;
^~~~
sublime.cpp:91:21: error: expected ‘:’ before ‘;’ token
case 35;
^
sublime.cpp:93:17: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:94:14: error: case label ‘36’ not within a switch statement
case 36;
^~~~
sublime.cpp:94:21: error: expected ‘:’ before ‘;’ token
case 36;
^
sublime.cpp:96:18: error: break statement not within loop or switch
break;
^~~~~
sublime.cpp:97:7: error: expected ‘(’ before ‘{’ token
}while{true);}
^
sublime.cpp:97:7: error: expected primary-expression before ‘{’ token
sublime.cpp:97:7: error: expected ‘)’ before ‘{’ token
sublime.cpp:97:12: error: expected ‘;’ before ‘)’ token
}while{true);}
^
sublime.cpp:97:14: error: expected ‘}’ at end of input
}while{true);}
^
Code:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main() {                                  //start of program
    int a;
    string program_name;
    do{
    a = (rand()%37);                        //assign output messages from number 0 to 37
    getline(cin, program_name);            //get keyboard input
    if(program_name == " Welcome to Sublime 1.0");
    continue;}
    switch(a)
    {                                          // display random text message on screen
             case 0;
                cout << "me and my family are surrounded by the universal most highest unbreakable protect from all types and kinds at all times";
                break;
             case 1;
                cout << "me and my family are surrounded by a forceshield at all times and anyone who tries to cause harm will become very ill instantly";
                break;
             case 2;
                cout << "i have the universe most powerful supernatural abilities at all times";
                break;
             case 3;
                cout << "i can control the weather of any type all times";
                break;
             case 4;
                cout << "i am insivible at all times";
                break;
             case 5;
                cout << "all evil against me and my family has now been completely removed ";
                break;
             case 6;
                 cout << "all magic used against me and my family is now broken and returned to senders one millions time fold";
                break;
             case 7;
                 cout << "i now have a beauitful wife with great personality and is loyal and faithul and trust worthy only to me and has good sense of humour and is kind and sensitive";
                break;
             case 8;
                 cout << "my child rainbow and other children are now born";
                break;
             case 9;
                 cout << "me and my wife now have as many kids as she wants";
                break;
             case 10;
                 cout << "i am always excellent in everything i do";
                break;
             case 11;
                 cout << "i have an amazing memory and learn and understand everything in an instant in all shapes and forms and types";
                break;
             case 12;
                 cout << "i am always excellent at selling online and offline of any product or service";
                break;
             case 13;
                 cout << "the university of worcester is now suffering the consequences of all the problems it and its students have caused in england";
                break;
             case 14;
                 cout << "all greedy and useless landlords in england have now been removed and repleced with decent caring and understanding ones";
                break;
             case 15;
                 cout << "i am always wealthy and rich and always have unlimited money";
                break;
             case 16;
                 cout << "i am always invisible";
                break;
             case 17;
                 cout << "i always have superpowers of all types and abilities at all times";
                break;
             case 18;
                 cout << "i am the best in the music business of the type of music i make"; 
                break;
             case 19;
                 cout << "i am always surrounded by those who love me only";
                break;
             case 20;
                 cout << "me and my family are surrounded by the universe most highest postive energy and vibrations only at all times";
                break;
             case 21;
                 cout << "i can control all types of weather and make it do whatever i want at all times"; 
                break;
             case 22;
                 cout << "i can see all  hidden and known at all times";
                break;
             case 33;
                 cout << "all those who take the piss out me and my family will end up homeless";
                break;
             case 34;
                 cout << "all hmos are now turned back into lovely family homes with decent families only";
                break;
             case 35;
                 cout << "matt richards who i know off and his friends and family and girlfriends and children are now all banished forever";
                break;
             case 36;
                 cout << "me and my family are surrounded by only true loving entities who help us at all times"; 
                 break;
}while{true);}

Last edited by twirl; 07-14-2019 at 03:33 PM.
 
Old 07-14-2019, 06:26 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,154
Blog Entries: 11

Rep: Reputation: 3077Reputation: 3077Reputation: 3077Reputation: 3077Reputation: 3077Reputation: 3077Reputation: 3077Reputation: 3077Reputation: 3077Reputation: 3077Reputation: 3077
Your curly braces are mangled.

It is not necessary to post all errors, but look at just the first two and see what they are telling you. The others will probably clear when you fix those.

The structure needs to be like this...

Code:
do{
   ...other stuff...
   switch(var){
      case '0': 
         ...
   }
}while(condition)
Yours is quite different, see if you can figure out why!

Last edited by astrogeek; 07-14-2019 at 06:36 PM. Reason: formatting
 
Old Yesterday, 05:50 AM   #6
hazel
Senior Member
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 3,020
Blog Entries: 7

Rep: Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584
You also have a mixed bracket pair in "{true)"! And if you count your opening and closing braces, you'll see they don't match.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sublime Text and Python. When you active REPL within Sublime Text 3 with Python, pop up version 2.7 as default, onto Ubuntu environment for arrayo Programming 1 04-05-2019 11:45 AM
[SOLVED] Sublime text editor: opening a second file causes the "waiting" cursor Red Squirrel Linux - Software 1 02-20-2015 07:58 AM
LXer: Atom vs. Sublime LXer Syndicated Linux News 0 07-20-2014 10:33 AM
LXer: Sublime Text: One Editor to Rule Them All? LXer Syndicated Linux News 0 10-22-2013 09:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration