• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 06:27
CET 12:27
KST 20:27
  • 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 Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump0Weekly 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
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 Weekly Cups (Nov 24-30): MaxPax, Clem, herO win
Tourneys
StarCraft2.fi 15th Anniversary Cup Tenacious Turtle Tussle Sparkling Tuna Cup - Weekly Open Tournament RSL Offline Finals Info - Dec 13 and 14! StarCraft Evolution League (SC Evo Biweekly)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night
Brood War
General
BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ Foreign Brood War Data analysis on 70 million replays MBCGame Torrents
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile ZeroSpace Megathread The Perfect Game
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 European Politico-economics QA Mega-thread US Politics Mega-thread Russo-Ukrainian War Thread The Big Programming 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? The Automated Ban List
Blogs
I decided to write a webnov…
DjKniteX
Physical Exertion During Gam…
TrAiDoS
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1264 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
Next event in 33m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 238
Rex 49
ProTech16
StarCraft: Brood War
GuemChi 1649
firebathero 792
Larva 496
Soma 350
Hyuk 322
Mini 316
actioN 298
ZerO 281
BeSt 232
Light 164
[ Show more ]
PianO 145
JYJ 143
Leta 130
Pusan 128
Dewaltoss 113
Killer 112
EffOrt 102
Snow 99
910 80
Rush 73
Sacsri 69
hero 64
Shine 61
ggaemo 50
Mind 50
Movie 50
JulyZerg 42
Aegong 40
ToSsGirL 40
yabsab 33
Shinee 29
Free 29
Sea.KH 26
sorry 22
ajuk12(nOOB) 21
zelot 20
Bale 12
scan(afreeca) 8
SilentControl 6
Icarus 2
Dota 2
Dendi485
singsing450
XcaliburYe137
NeuroSwarm84
League of Legends
JimRising 373
C9.Mang0221
Reynor108
Counter-Strike
olofmeister1807
shoxiejesuss638
x6flipin202
allub171
Other Games
summit1g9493
B2W.Neo321
crisheroes273
Fuzer 229
ZerO(Twitch)8
Organizations
Other Games
BasetradeTV153
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 12 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota273
League of Legends
• Jankos1846
Upcoming Events
WardiTV 2025
33m
StarCraft2.fi
4h 33m
PiGosaur Monday
13h 33m
StarCraft2.fi
1d 5h
Tenacious Turtle Tussle
1d 12h
The PondCast
1d 22h
WardiTV 2025
2 days
StarCraft2.fi
2 days
WardiTV 2025
3 days
StarCraft2.fi
3 days
[ Show More ]
RSL Revival
3 days
IPSL
4 days
Sziky vs JDConan
RSL Revival
4 days
Classic vs TBD
herO vs Zoun
WardiTV 2025
5 days
IPSL
5 days
Tarson vs DragOn
Wardi Open
6 days
Monday Night Weeklies
6 days
Replay Cast
6 days
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

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

Ongoing

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

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
RSL Offline Finals
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.