• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 06:07
CEST 12:07
KST 19:07
  • 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
Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5TL.net Map Contest #21 - Finalists4Team TLMC #5: Vote to Decide Ladder Maps!0
Community News
5.0.15 Patch Balance Hotfix (2025-10-8)59Weekly Cups (Sept 29-Oct 5): MaxPax triples up3PartinG joins SteamerZone, returns to SC2 competition275.0.15 Balance Patch Notes (Live version)119$2,500 WardiTV TL Map Contest Tournament 154
StarCraft 2
General
PartinG joins SteamerZone, returns to SC2 competition Geoff 'iNcontroL' Robinson has passed away 5.0.15 Patch Balance Hotfix (2025-10-8) Classic Games #3: Rogue vs Serral at BlizzCon Team TLMC #5: Winners Announced!
Tourneys
SC2's Safe House 2 - October 18 & 19 RSL Offline Finals Dates + Ticket Sales! SC4ALL $6,000 Open LAN in Philadelphia Sparkling Tuna Cup - Weekly Open Tournament $2,500 WardiTV TL Map Contest Tournament 15
Strategy
Custom Maps
External Content
Mutation # 494 Unstable Environment Mutation # 493 Quick Killers Mutation # 492 Get Out More Mutation # 491 Night Drive
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ I'm making videos again BW General Discussion Question regarding recent ASL Bisu vs Larva game Whose hotkey signature is this?
Tourneys
[Megathread] Daily Proleagues [ASL20] Ro8 Day 4 Small VOD Thread 2.0 [ASL20] Ro8 Day 3
Strategy
Current Meta TvZ Theorycraft - Improving on State of the Art Proposed Glossary of Strategic Uncertainty 9 hatch vs 10 hatch vs 12 hatch
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread ZeroSpace Megathread Dawn of War IV Path of Exile
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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
SPIRED by.ASL Mafia {211640} TL Mafia Community Thread
Community
General
US Politics Mega-thread Stop the Construction YouTube Thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread
Fan Clubs
The herO Fan Club! The Happy Fan Club!
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
Formula 1 Discussion 2024 - 2026 Football Thread MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
How "Not Like Us" ripped of…
Peanutsc
From Tilt to Ragequit:The Ps…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1346 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
CranKy Ducklings
10:00
Sea Duckling Open #139
CranKy Ducklings20
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 358
RotterdaM 196
MindelVK 28
Railgan 12
Rex 1
StarCraft: Brood War
Hyuk 1112
Shuttle 612
actioN 573
Larva 481
Zeus 343
firebathero 329
BeSt 325
Flash 264
EffOrt 205
sorry 176
[ Show more ]
Leta 174
Mini 78
Shine 51
Light 44
ZerO 37
Mong 36
Soulkey 31
zelot 26
HiyA 20
Sharp 11
Sacsri 9
Hm[arnc] 5
Britney 1
Dota 2
XcaliburYe440
Counter-Strike
Stewie2K606
Heroes of the Storm
Khaldor180
Other Games
summit1g3485
singsing1810
Happy221
Fuzer 95
Mew2King47
ZerO(Twitch)4
Organizations
Other Games
gamesdonequick667
BasetradeTV63
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH191
• LUISG 28
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos1898
• Stunt664
Upcoming Events
Map Test Tournament
54m
MaxPax vs Ryung
TBD vs Classic
Zoun vs YoungYakov
Reynor vs Cure
ByuN vs Lambo
TBD vs Clem
OSC
4h 54m
[BSL 2025] Weekly
7h 54m
Safe House 2
7h 54m
Sparkling Tuna Cup
23h 54m
Map Test Tournament
1d
TBD vs Spirit
TBD vs herO
OSC
1d 1h
IPSL
1d 8h
Bonyth vs Art_Of_Turtle
Razz vs rasowy
Afreeca Starleague
1d 23h
Barracks vs Snow
Afreeca Starleague
2 days
Soma vs Bisu
[ Show More ]
The PondCast
4 days
CranKy Ducklings
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
Maestros of the Game
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
WardiTV TLMC #15
EC S1
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 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.