• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 16:06
CET 22:06
KST 06:06
  • 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
RSL Revival - 2025 Season Finals Preview7RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3
StarCraft 2
General
RSL Revival - 2025 Season Finals Preview Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced
Tourneys
RSL Offline Finals Info - Dec 13 and 14! Tenacious Turtle Tussle 2025 RSL Offline Finals Dates + Ticket Sales! Sparkling Tuna Cup - Weekly Open Tournament StarCraft2.fi 15th Anniversary Cup
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 504 Retribution Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress
Brood War
General
How Rain Became ProGamer in Just 3 Months BGH Auto Balance -> http://bghmmr.eu/ [BSL21] RO8 Bracket & Prediction Contest BW General Discussion FlaSh on: Biggest Problem With SnOw's Playstyle
Tourneys
[ASL20] Grand Finals [BSL21] RO8 - Day 2 - Sunday 21:00 CET [BSL21] RO8 - Day 1 - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Game Theory for Starcraft Fighting Spirit mining rates Current Meta
Other Games
General Games
Dawn of War IV Path of Exile Stormgate/Frost Giant Megathread Awesome Games Done Quick 2026! Nintendo Switch Thread
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
Mafia Game Mode Feedback/Ideas Survivor II: The Amazon Sengoku Mafia TL Mafia Community Thread
Community
General
Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread US Politics Mega-thread YouTube Thread European Politico-economics QA Mega-thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
TL+ Announced Where to ask questions and add stream?
Blogs
How Sleep Deprivation Affect…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1463 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
BSL 21
20:00
RO8 - Day 2
Tech vs Cross
Bonyth vs eOnzErG
ZZZero.O287
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 480
IndyStarCraft 172
JuggernautJason106
DisKSc2 32
UpATreeSC 17
StarCraft: Brood War
Britney 15990
Calm 2366
Shuttle 469
Mini 334
ZZZero.O 287
EffOrt 181
Dewaltoss 75
ggaemo 62
Dota 2
Gorgc5417
420jenkins222
LuMiX1
Counter-Strike
fl0m9737
byalli549
Super Smash Bros
hungrybox130
Heroes of the Storm
Khaldor533
Liquid`Hasu484
Other Games
Grubby4342
B2W.Neo544
ArmadaUGS155
Fuzer 81
OptimusSC21
Organizations
Other Games
gamesdonequick1521
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• HeavenSC 44
• sitaska23
• Adnapsc2 20
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• Airneanach27
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV506
Other Games
• imaqtpie2468
• Shiphtur575
Upcoming Events
Replay Cast
11h 54m
Wardi Open
14h 54m
Monday Night Weeklies
19h 54m
Sparkling Tuna Cup
1d 12h
OSC
2 days
YoungYakov vs Mixu
ForJumy vs TBD
Percival vs TBD
Shameless vs TBD
Replay Cast
3 days
The PondCast
3 days
OSC
4 days
CranKy Ducklings
5 days
SC Evo League
5 days
[ Show More ]
BSL 21
5 days
Sparkling Tuna Cup
6 days
BSL 21
6 days
Liquipedia Results

Completed

Acropolis #4 - TS3
RSL Revival: Season 3
Kuram Kup

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
Slon Tour Season 2
WardiTV 2025
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22

Upcoming

CSL 2025 WINTER (S19)
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
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 © 2025 TLnet. All Rights Reserved.