SunQuest
           C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 7th, 2008, 12:37 AM
Hanlon Hanlon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 Hanlon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 50 sec
Reputation Power: 0
If Do statement + more, need help

Ok, Im a beginner using C++ as my first language. I use the program dev c++. Im trying to create my first program by myself but I, it calculates the area and perimeter of the square, circle and triangle. However, I don't know how to make it pick the shape. I've been trying to make it do:

pick: 1 , 2 or 3
and then when you pick it, the program goes to the correct equation to solve it.

anyone mind helping me? This is my script. The "if (shape = 1)"
does nothing.

#include<iostream>
using namespace std;

int main()
{
system("TITLE Hanlon's Geometric Calculator");
system("COLOR 2");
char eChar;
int shape;
double dnumber1;
double dnumber2;
double dnumber3;
double dnumber4;
double dradius;
char cDoagain;

do
{
system("CLS");
cout << "What Type Of Geometric Shape" << " // 1.Square // 2.Triangle // 3.Circle // " << endl;
cin >> shape;

if (shape == 1);
{
cout << "Enter Side 1: " << endl;
cin >> dnumber1;
cout << "Enter Side2: " << endl;
cin >> dnumber2;
cout << "The Area Is: " << dnumber1 << " * " << dnumber2 << " = " << (dnumber1 * dnumber2) << endl;
cout << "The Perimeter Is: " << dnumber1 << " *2 + " << dnumber2 << " *2 = " << ((dnumber1 *2) + (dnumber2 *2)) << endl;
}
if (shape == 2);
{
cout << "Enter Base: " << endl;
cin >> dnumber1;
cout << "Enter Height: " << endl;
cin >> dnumber2;
cout << "Enter Side 1: " << endl;
cin >> dnumber3;
cout << "Enter Side 2: " << endl;
cin >> dnumber4;
cout << "The Area Is: " << dnumber1 << " * " << dnumber2 << " /2 " << " = " << ((dnumber1 * dnumber2)/2) << endl;
cout << "The Perimeter Is: " << dnumber1 << " + " << dnumber3 << " + " << dnumber4 << " = " << (dnumber1 + dnumber2 + dnumber3) << endl;
}
if (shape == 3);
{
cout << "Enter Radius: " << endl;
cin >> dradius;
cout << "The Area Is: " <<" 3.14159265 " << " * " << dradius << " ^2 " << " = " << (3.14159265 * dradius * dradius) << endl;
cout << "The Perimeter Is: " << " 2 " << " * " << " 3.14159265 " << " * " << dradius << " = " << (2 * 3.14159265 * dradius) << endl;
}

cout << "Wanna Start Again? (y or n)" << endl;
cin >> cDoagain;
}while (cDoagain == 'Y' || cDoagain =='y');

system("PAUSE");
return 0;
}

Thanks Alot

Reply With Quote
  #2  
Old May 7th, 2008, 01:35 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is online now
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,793 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 6 h 53 m 57 sec
Reputation Power: 434
1. Use code tags to retain your program's indentation. It's unreadable otherwise. If you continue in your sinful ways, then you will be constantly castigated for your transgressions and rightfully so.

2. Read the "READ THIS FIRST" sticky. That's what it's there for. Duh?

3. You're not writing a script; you're writing a program. C++ is not a scripting language. I can't imagine why you would think that it is.


Your if (shape = 1) would be wrong, since it assigns the value of one to shape. But at least you don't repeat that mistake in your code, where you properly write it as if (shape == 1) and which is the comparison operation.

Also, you should be doing if () {} else if {} else if {} else {}. Or using a switch statement. BTW, that else at the end is to handle the case where the user enters something that's not 1, 2, or 3. Users are undisciplined onery critters who rarely provide proper input; sizablegrin, a seasoned and grizzly denizen of these-here parts, will inform you in no uncertain terms that you must always be ready to handle totally bogus input.

But the killer is that none of your if-statements have any body, as you can see highlighted in red:
Code:
    if (shape == 1);
    {
        cout << "Enter Side 1: " << endl;
        cin >> dnumber1;
        cout << "Enter Side2: " << endl;
        cin >> dnumber2;
        cout << "The Area Is: " << dnumber1 << " * " << dnumber2 << " = " <<
                     (dnumber1 * dnumber2) << endl;
        cout << "The Perimeter Is: " << dnumber1 << " *2 + " << dnumber2 << 
                    " *2 = " << ((dnumber1 *2) + (dnumber2 *2)) << endl;
    } 
    if (shape == 2);
    {
        cout << "Enter Base: " << endl;
        cin >> dnumber1;
        cout << "Enter Height: " << endl;
        cin >> dnumber2;
        cout << "Enter Side 1: " << endl;
        cin >> dnumber3;
        cout << "Enter Side 2: " << endl;
        cin >> dnumber4;
        cout << "The Area Is: " << dnumber1 << " * " << dnumber2 << " /2 " << 
                    " = " << ((dnumber1 * dnumber2)/2) << endl;
        cout << "The Perimeter Is: " << dnumber1 << " + " << dnumber3 << 
                    " + " << dnumber4 << " = " << (dnumber1 + dnumber2 + dnumber3) 
                    << endl;
    }
    if (shape == 3);
    {
        cout << "Enter Radius: " << endl;
        cin >> dradius;
        cout << "The Area Is: " <<" 3.14159265 " << " * " << dradius << 
                    " ^2 " << " = " << (3.14159265 * dradius * dradius) << endl;
        cout << "The Perimeter Is: " << " 2 " << " * " << " 3.14159265 " << 
                    " * " << dradius << " = " << (2 * 3.14159265 * dradius) << endl; 
    }

By placing those semicolons right after the if condition, you tell the compiler that that's the end of the if-statement. That means that those code blocks that you had intended as being the bodies of the bodies of those if-statements -- well, the complier does not see them as such, but rather as code blocks to be executed unconditionally. Which means that they would have all been executed.

Which means that each and every one of those shapes would have been executed. And you neglected to provide us that very valuable piece of information! That wasn't very nice of you.

When you have a problem to be solved, one which generates some kind of error, then you need to inform us of that error. If I had a nickel for every time we had to remind a newbie that we don't read minds, I could have retired long ago. We do not read minds. You have to tell us these things (something that my ex-wife could never understand).


PS
Just in case your reading comprehension is not up to snuff, lose those red semicolons.
Comments on this post
Joseph Taylor agrees!

Last edited by dwise1_aol : May 7th, 2008 at 01:47 AM.

Reply With Quote
  #3  
Old May 7th, 2008, 01:56 AM
Hanlon Hanlon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 Hanlon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 50 sec
Reputation Power: 0
Re:

Srry, like I said Im a noobie, just making noobie mistakes

but thx this helped alot, I finished the program

and it wasnt the fact that it didn't work, just couldnt make it pick a shape

thx again

Reply With Quote
  #4  
Old May 7th, 2008, 02:43 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is online now
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,793 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 6 h 53 m 57 sec
Reputation Power: 434
Keep in mind what you need to do when you make another post in this forum. Others won't be anywhere near as nice as I was.

Ie, it doesn't take much to play nice around here. But you'll definitely be told when you're not playing nice.

Reply With Quote
  #5  
Old May 7th, 2008, 07:37 AM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Stubborn ol' L'User
Click here for more information.
 
Join Date: Jun 2005
Posts: 3,036 sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 23 h 52 m 33 sec
Reputation Power: 1440
I think I see the problem. We should rename the thread:
New users - HOW TO POST A QUESTION - READ THIS FIRST
to
Noobie - HOW TO POST A QUESTION - READ THIS FIRST
Comments on this post
ptr2void agrees: Don't forget Noob, n00b, newbie, free pie, freshers
__________________
C/C++ pointers (Original in the "Commonly Asked Questions" thread).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > If Do statement + more, need help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway