• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 00:36
CET 06:36
KST 14:36
  • 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
[BSL21] Ro.16 Group Stage (C->B->A->D)1Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win2RSL Season 3: RO16 results & RO8 bracket13Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge2[TLMC] Fall/Winter 2025 Ladder Map Rotation14
StarCraft 2
General
When will we find out if there are more tournament Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win SC: Evo Complete - Ranked Ladder OPEN ALPHA Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge RSL Season 3: RO16 results & RO8 bracket
Tourneys
Tenacious Turtle Tussle RSL Revival: Season 3 $5,000+ WardiTV 2025 Championship StarCraft Evolution League (SC Evo Biweekly) Constellation Cup - Main Event - Stellar Fest
Strategy
Ride the Waves in Surf City: Why Surfing Lessons H
Custom Maps
Map Editor closed ?
External Content
Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death
Brood War
General
Which season is the best in ASL? FlaSh on: Biggest Problem With SnOw's Playstyle soO on: FanTaSy's Potential Return to StarCraft Data analysis on 70 million replays 2v2 maps which are SC2 style with teams together?
Tourneys
[BSL21] RO16 Tie Breaker - Group B - Sun 21:00 CET [BSL21] GosuLeague T1 Ro16 - Tue & Thu 22:00 CET [Megathread] Daily Proleagues [BSL21] RO16 Tie Breaker - Group A - Sat 21:00 CET
Strategy
Game Theory for Starcraft How to stay on top of macro? Current Meta PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread Should offensive tower rushing be viable in RTS games? Nintendo Switch Thread Path of Exile Clair Obscur - Expedition 33
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
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
The Health Impact of Joining…
TrAiDoS
Dyadica Evangelium — Chapt…
Hildegard
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2756 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
PiGosaur Cup
01:00
#59
SteadfastSC176
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SteadfastSC 176
SortOf 30
StarCraft: Brood War
Larva 952
Snow 143
Sharp 78
Noble 42
Icarus 6
Soulkey 2
BeSt 0
Dota 2
monkeys_forever575
League of Legends
JimRising 639
Counter-Strike
C9.Mang0340
Other Games
summit1g7813
WinterStarcraft344
ViBE161
Trikslyr28
trigger1
Organizations
Other Games
gamesdonequick1038
Dota 2
PGL Dota 2 - Main Stream289
StarCraft: Brood War
UltimateBattle 100
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki22
• RayReign 15
• Diggity3
• ZZZeroYoutube
• STPLYoutube
• BSLYoutube
League of Legends
• Rush1178
• Lourlo1106
• HappyZerGling95
Other Games
• Scarra1768
Upcoming Events
Replay Cast
3h 24m
Wardi Open
6h 24m
OSC
7h 24m
Tenacious Turtle Tussle
18h 24m
The PondCast
1d 4h
Replay Cast
1d 17h
OSC
2 days
LAN Event
2 days
Replay Cast
2 days
Replay Cast
3 days
[ Show More ]
WardiTV Korean Royale
3 days
Sparkling Tuna Cup
4 days
WardiTV Korean Royale
4 days
Replay Cast
4 days
Wardi Open
5 days
Monday Night Weeklies
5 days
Replay Cast
5 days
Wardi Open
6 days
Liquipedia Results

Completed

SOOP Univ League 2025
RSL Revival: Season 3
Eternal Conflict S1

Ongoing

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

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
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.