• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 08:31
CET 14:31
KST 22:31
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
ByuL: The Forgotten Master of ZvT28Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8
Community News
Weekly Cups (Feb 16-22): MaxPax doubles0Weekly Cups (Feb 9-15): herO doubles up2ACS replaced by "ASL Season Open" - Starts 21/0247LiuLi Cup: 2025 Grand Finals (Feb 10-16)46Weekly Cups (Feb 2-8): Classic, Solar, MaxPax win2
StarCraft 2
General
Nexon's StarCraft game could be FPS, led by UMS maker ByuL: The Forgotten Master of ZvT How do you think the 5.0.15 balance patch (Oct 2025) for StarCraft II has affected the game? Oliveira Would Have Returned If EWC Continued Behind the Blue - Team Liquid History Book
Tourneys
PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar) RSL Season 4 announced for March-April WardiTV Team League Season 10 The Dave Testa Open #11 Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026] Map Editor closed ?
External Content
Mutation # 514 Ulnar New Year The PondCast: SC2 News & Results Mutation # 513 Attrition Warfare Mutation # 512 Overclocked
Brood War
General
CasterMuse Youtube Soma Explains: JD's Unrelenting Aggro vs FlaSh ACS replaced by "ASL Season Open" - Starts 21/02 BGH Auto Balance -> http://bghmmr.eu/ TvZ is the most complete match up
Tourneys
Escore Tournament StarCraft Season 1 [Megathread] Daily Proleagues [LIVE] [S:21] ASL Season Open Day 1 Small VOD Thread 2.0
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Zealot bombing is no longer popular?
Other Games
General Games
Battle Aces/David Kim RTS Megathread Path of Exile Nintendo Switch Thread Beyond All Reason New broswer game : STG-World
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Mexico's Drug War Canadian Politics Mega-thread Russo-Ukrainian War Thread Ask and answer stupid questions here!
Fan Clubs
The IdrA Fan Club The herO Fan Club!
Media & Entertainment
[Req][Books] Good Fantasy/SciFi books [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TL MMA Pick'em Pool 2013
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
YOUTUBE VIDEO
XenOsky
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Inside the Communication of …
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1742 users

Programming question

Blogs > gumbum8
Post a Reply
gumbum8
Profile Blog Joined December 2008
United States721 Posts
Last Edited: 2010-02-05 20:47:58
February 05 2010 20:35 GMT
#1
Hello TeamLiqiud!
I hate to make a topic over such a trivial topic, but I need help and noone else I know has any idea how to help me. So I'm having difficulty with a program (I'm newb) I've been working on, trying to make better and better (a calculator program). Recently I made an improvement, but after I changed it I'm getting an error I've never had before, it says "expected init- declarator before "using"". I took off the improvements and I still get the error, so I'm thinking maybe it could be a bug with the compiler? I'm not sure. Here's the main page, it's the only one with the error right now, and the problem is line 4:
//program that acts as a basic calculator
#include <iostream>
#include "math.h"
using namespace std;

int main()
{
for (;;)
{cout << "hello, this is the calculator!" << endl;
cout << "chose your operation with a number: 1 for addition, 2 for subra" <<
"ction, 3 for multiplication, and 4 for division, and 5 to square. To quit, press any letter." << endl << endl;
int s; //s is variable for selection, is an interger
cin >> s;
if (!cin.good())
{
cout << "Your input is invalid and has terminated the program." << endl;
break;
}
if (s == 1)
{
cout << "choose your first and second number." << endl;
int a;
int b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "your solution is " << add (a, b) << endl << endl;
continue;
}
if (s == 2)
{
cout << "choose your first and second number." << endl;
int a;
int b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "your solution is " << subtract (a, b) << endl << endl;
continue;
}
if (s == 3)
{
cout << "choose your first and second number." << endl;
int a;
int b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "your solution is " << multiply (a, b) << endl << endl;
continue;
}
if (s == 4)
{
cout << "choose your first and second number." << endl;
float a;
float b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "your solution is " << divide (a, b) << endl << endl;
continue;
}
if (s==5)
{
cout << "Choose the number to be squared." << endl;
int a;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "your solution is " << square (a) << endl << endl;
continue;
}
else
{
cout << "Thats not a valid operation." << endl << endl;
continue;
};
system("PAUSE");
}
system("PAUSE");
return (0);
}


I've been coding for about a month, so please don't laugh at me
Thanks for any help!

but really, has anyone REALLY been far even as decided to use even go want to do look more like?
gumbum8
Profile Blog Joined December 2008
United States721 Posts
February 05 2010 20:36 GMT
#2
What a fun coincidence that the ; ) in the for loop makes a
XD
but really, has anyone REALLY been far even as decided to use even go want to do look more like?
MasterOfChaos
Profile Blog Joined April 2007
Germany2896 Posts
February 05 2010 20:39 GMT
#3
use the [ code ] tag
LiquipediaOne eye to kill. Two eyes to live.
b3h47pte
Profile Blog Joined May 2007
United States1317 Posts
Last Edited: 2010-02-05 20:45:48
February 05 2010 20:45 GMT
#4
I posted your code in VS2008 and compiles fine but i did have to take out the lines where you display the answers as add, divide and what not are not defined and from what i've seen, you didn't seem to define them either. Is there stuff you're not showing us?

What compiler are you using?
Alphonsse
Profile Blog Joined March 2009
United States518 Posts
February 05 2010 20:48 GMT
#5
Is "math.h" a code file that you wrote? I'm guessing so, and my guess is that that file is the source of your errors.
gumbum8
Profile Blog Joined December 2008
United States721 Posts
February 05 2010 20:49 GMT
#6
On February 06 2010 05:45 b3h47pte wrote:
I posted your code in VS2008 and compiles fine but i did have to take out the lines where you display the answers as add, divide and what not are not defined and from what i've seen, you didn't seem to define them either. Is there stuff you're not showing us?

What compiler are you using?

I'm using an include file, just playing with headers.
Thanks! I had no idea about the code tag, sorry.
Should I add the include files or just repost with the functions defined in the same program?
but really, has anyone REALLY been far even as decided to use even go want to do look more like?
Alphonsse
Profile Blog Joined March 2009
United States518 Posts
February 05 2010 20:50 GMT
#7
Just post the header file.
gumbum8
Profile Blog Joined December 2008
United States721 Posts
February 05 2010 20:56 GMT
#8
On February 06 2010 05:48 Alphonsse wrote:
Is "math.h" a code file that you wrote? I'm guessing so, and my guess is that that file is the source of your errors.

.... I'm really bad at making blogs.
After seriously an hour and 15 minutes of checking {s and }s, semicolons and shit, I find that I left a semicolon out of my header file.

Sorry for the shitty fail blogs, but it helped.
but really, has anyone REALLY been far even as decided to use even go want to do look more like?
Alphonsse
Profile Blog Joined March 2009
United States518 Posts
February 05 2010 20:57 GMT
#9
Np, just remember that whenever you see an error on a line of code that immediately follows a #include statement, that generally means the error is in the file that you included.
Mystlord *
Profile Blog Joined July 2008
United States10264 Posts
February 05 2010 20:59 GMT
#10
Just a small note. I'd discourage using the same names for your own headers as those already included in the C library. Makes things a little more confusing
It is impossible to be a citizen if you don't make an effort to understand the most basic activities of your government. It is very difficult to thrive in an increasingly competitive world if you're a nation of doods.
FastEddieV
Profile Blog Joined July 2007
United States614 Posts
February 05 2010 21:12 GMT
#11
Yeah I was going to say, isn't there already a math.h? At least way back when I was learning to code there was...
platinum? more like leaf
yh8c4
Profile Blog Joined July 2009
108 Posts
February 05 2010 21:15 GMT
#12
what you could do to improve readability:

- better indentation
- instead of if (s == 1), if (s == 2), etc use the switch statement
- put the code for your operations into seperate functions and call them from the switch statement

apart from that, good work, keep on going
rabidch
Profile Joined January 2010
United States20289 Posts
Last Edited: 2010-02-05 21:21:42
February 05 2010 21:20 GMT
#13
holy crap thats some MOTHAFKING UGLY indenting style
I cleaned it up a bit and added some stuff so it'll compile but there's still a lot of redundancy and bad coding style

I don't get any warnings or errors from VS2008 i'll look at gcc later

#include <iostream>

using namespace std;

int add(int a, int b) { return a + b; }
int subtract(int a, int b) { return a - b; }
int multiply(int a, int b) { return a * b; }
float divide(float a, float b) { return a/b; }
int square(int a) { return a * a; }

int main()
{
for (;;)
{
cout << "Hello, this is the calculator!" << endl;
cout << "Choose your operation with a number:"
<< "1 for addition, 2 for subraction, 3 for multiplication, and 4 for division, and 5 to square."
<< "To quit, input any letter." << endl << endl;

int s; // "s" is variable for selection
cin >> s;
if (!cin.good())
{
cout << "Your input is invalid and the program will be terminated." << endl;
break;
}
if (s == 1)
{
cout << "choose your first and second number." << endl;
int a;
int b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "your solution is " << add (a, b) << endl << endl;
continue;
}
if (s == 2)
{
cout << "choose your first and second number." << endl;
int a;
int b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "your solution is " << subtract (a, b) << endl << endl;
continue;
}
if (s == 3)
{
cout << "choose your first and second number." << endl;
int a;
int b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "your solution is " << multiply (a, b) << endl << endl;
continue;
}
if (s == 4)
{
cout << "choose your first and second number." << endl;
float a;
float b;

// INPUT A
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
// INPUT B
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}

if (b == 0)
{
cout << "YOU CAN'T DIVIDE BY 0." << endl;
break;
}

cout << "Your solution is " << divide (a, b) << endl << endl;
continue;
}
if (s == 5)
{
cout << "Choose the number to be squared." << endl;
int a;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "your solution is " << square (a) << endl << endl;
continue;
}
else
{
cout << "Thats not a valid selection." << endl << endl;
continue;
}
system("PAUSE");
}
system("PAUSE");
return (0);
}
LiquidDota StaffOnly a true king can play the King.
Obzy
Profile Joined April 2009
United States525 Posts
Last Edited: 2010-02-05 21:31:32
February 05 2010 21:30 GMT
#14
I'm not taking an incredibly detailed look, but just eyeballing it, one suggestion (that matters very little) is to throw in a function for

if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}


Might as well make that into a function and just call it every time to make things more readable? I haven't programmed in forever though, so maybe that's not a very good idea ._.; Just a thought.
I have nothing to put here. Obzy#1821 on Bnet.
jalstar
Profile Blog Joined September 2009
United States8198 Posts
Last Edited: 2010-02-05 21:48:30
February 05 2010 21:45 GMT
#15
+ Show Spoiler +


#include <iostream>

using namespace std;

int add(int a, int b) { return a + b; }
int subtract(int a, int b) { return a - b; }
int multiply(int a, int b) { return a * b; }
float divide(float a, float b) { return a/b; }
int square(int a) { return a * a; }
char temp;

int main()
{
for (;;)
{
cout << "Hello, this is the calculator!" << endl;
cout << "Choose your operation with a number:\n"
<< "1 for addition\n2 for subraction\n3 for multiplication\n4 for division\n5 to square.\n\n"
<< "To quit, input any letter." << endl << endl;

int s; // "s" is variable for selection
cin >> s;
if (!cin.good())
{
cout << "Your input is invalid and the program will be terminated." << endl;
break;
}
if (s == 1)
{
cout << "Choose your first and second number." << endl;
int a;
int b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "Your solution is " << add (a, b) << endl << endl;
continue;
}
if (s == 2)
{
cout << "Choose your first and second number." << endl;
int a;
int b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "Your solution is " << subtract (a, b) << endl << endl;
continue;
}
if (s == 3)
{
cout << "Choose your first and second number." << endl;
int a;
int b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "Your solution is " << multiply (a, b) << endl << endl;
continue;
}
if (s == 4)
{
cout << "choose your first and second number." << endl;
float a;
float b;

// INPUT A
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
// INPUT B
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}

if (b == 0)
{
cout << "YOU CAN'T DIVIDE BY 0." << endl;
break;
}

cout << "Your solution is " << divide (a, b) << endl << endl;
continue;
}
if (s == 5)
{
cout << "Choose the number to be squared." << endl;
int a;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "Your solution is " << square (a) << endl << endl;
continue;
}
else
{
cout << "Thats not a valid selection." << endl << endl;
continue;
}
cin >> temp;
}
cin >> temp;
return (0);
}



i dunno that much about programming, just made the output look nicer

no errors in dev c++

edit: oooohhhhh

you should tell the user that it crashes if you don't use integers
stoned_rabbit
Profile Blog Joined November 2009
United States324 Posts
Last Edited: 2010-02-05 23:10:05
February 05 2010 23:06 GMT
#16
On February 06 2010 06:45 jalstar wrote:
+ Show Spoiler +


#include <iostream>

using namespace std;

int add(int a, int b) { return a + b; }
int subtract(int a, int b) { return a - b; }
int multiply(int a, int b) { return a * b; }
float divide(float a, float b) { return a/b; }
int square(int a) { return a * a; }
char temp;

int main()
{
for (;
{
cout << "Hello, this is the calculator!" << endl;
cout << "Choose your operation with a number:\n"
<< "1 for addition\n2 for subraction\n3 for multiplication\n4 for division\n5 to square.\n\n"
<< "To quit, input any letter." << endl << endl;

int s; // "s" is variable for selection
cin >> s;
if (!cin.good())
{
cout << "Your input is invalid and the program will be terminated." << endl;
break;
}
if (s == 1)
{
cout << "Choose your first and second number." << endl;
int a;
int b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "Your solution is " << add (a, b) << endl << endl;
continue;
}
if (s == 2)
{
cout << "Choose your first and second number." << endl;
int a;
int b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "Your solution is " << subtract (a, b) << endl << endl;
continue;
}
if (s == 3)
{
cout << "Choose your first and second number." << endl;
int a;
int b;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "Your solution is " << multiply (a, b) << endl << endl;
continue;
}
if (s == 4)
{
cout << "choose your first and second number." << endl;
float a;
float b;

// INPUT A
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
// INPUT B
cin >> b;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}

if (b == 0)
{
cout << "YOU CAN'T DIVIDE BY 0." << endl;
break;
}

cout << "Your solution is " << divide (a, b) << endl << endl;
continue;
}
if (s == 5)
{
cout << "Choose the number to be squared." << endl;
int a;
cin >> a;
if (!cin.good())
{
cout << "Your input is invalid." << endl;
break;
}
cout << "Your solution is " << square (a) << endl << endl;
continue;
}
else
{
cout << "Thats not a valid selection." << endl << endl;
continue;
}
cin >> temp;
}
cin >> temp;
return (0);
}



i dunno that much about programming, just made the output look nicer

no errors in dev c++

edit: oooohhhhh

you should tell the user that it crashes if you don't use integers


or just verify the input values to make sure they're integers...

edit.. btw i just looked at your code and its got some serious issues. dont use continue statements ever. just use a big switch statement... like
switch(s)
case 1:
code;
break;

etc etc. makes it easier to read and doesn't violate one of the basic programming principles that you should be learning if you're in a class. this also lets you verify input once and make sure everything is good (you'll still need to cover the divide by zero case in the division case but it's better than verifying the same input 6? times)
Please log in or register to reply.
Live Events Refresh
PiG Sty Festival
10:00
Twitch Plays + Serral Holdout
Serral vs TBDLIVE!
PiGStarcraft896
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft896
Lowko332
ProTech59
StarCraft: Brood War
Britney 39304
Calm 10294
Rain 2361
Horang2 1969
Sea 1894
Bisu 1612
Jaedong 605
firebathero 364
BeSt 363
Stork 345
[ Show more ]
Shuttle 343
Larva 208
Last 202
ZerO 165
Soma 153
EffOrt 117
Mong 79
Rush 76
Mind 62
hero 56
ToSsGirL 53
[sc1f]eonzerg 47
Sharp 45
Barracks 35
Backho 33
Aegong 31
Hm[arnc] 29
Shinee 28
sSak 27
IntoTheRainbow 25
NotJumperer 21
scan(afreeca) 18
GoRush 17
sorry 14
Terrorterran 12
Noble 9
Icarus 7
Dota 2
qojqva852
XcaliburYe92
Counter-Strike
olofmeister2015
x6flipin644
oskar77
Other Games
singsing2115
B2W.Neo796
hiko345
crisheroes317
XaKoH 118
QueenE89
Mew2King84
ZerO(Twitch)8
Organizations
Counter-Strike
PGL366
Other Games
gamesdonequick278
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 89
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos1573
• Nemesis789
• TFBlade505
Upcoming Events
Replay Cast
10h 29m
Korean StarCraft League
1d 13h
CranKy Ducklings
1d 20h
OSC
1d 21h
SC Evo Complete
1d 23h
DaveTesta Events
2 days
AI Arena Tournament
2 days
Replay Cast
2 days
Sparkling Tuna Cup
2 days
uThermal 2v2 Circuit
3 days
[ Show More ]
Replay Cast
3 days
Wardi Open
3 days
Monday Night Weeklies
4 days
Replay Cast
4 days
Replay Cast
5 days
Replay Cast
6 days
The PondCast
6 days
KCM Race Survival
6 days
Liquipedia Results

Completed

Proleague 2026-02-22
LiuLi Cup: 2025 Grand Finals
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Acropolis #4 - TS5
Jeongseon Sooper Cup
Spring Cup 2026
WardiTV Winter 2026
PiG Sty Festival 7.0
Nations Cup 2026
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025

Upcoming

[S:21] ASL SEASON OPEN 2nd Round
[S:21] ASL SEASON OPEN 2nd Round Qualifier
ASL Season 21: Qualifier #1
ASL Season 21: Qualifier #2
ASL Season 21
Acropolis #4 - TS6
Acropolis #4
HSC XXIX
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
RSL Revival: Season 4
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
FISSURE Playground #3
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.