Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 06-18-2011, 07:19 PM   #1
Baseband Member
 
Join Date: Jun 2011
Posts: 30
Default I need C++ help.

This is just the start of my calculator I'm trying to make but it's not turning out well. This is just the begening and I'm going to keep going on later but I used this script. If you want to try the output put it in Visual Studios(If you have it).

Please help me!

Code:
#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
    cout << "This is my calculator. It follows the BEDMAS Rules. \n" ;
    signed float number1 ;
    signed float number2 ;
    signed float number3 ;

    signed float finalequation ;

    cout << "Enter two or three numbers. \n" ;
    cout << "Use * to multiply. \n" ;
    cout << "Use + to add. \n" ;
    cout << "Use - to subtract. \n" ;
    cout << "Use / to divide. \n" ;
    cin.get();

    if(number1 + number2 + number3 = finalequation)
        cout << "You just added"; cout << number1; cout << " to "; cout << number2; cout << "to"; cout << number3; cout << "!";

    cin.get();
    return 0;
}
__________________

JacobP is offline   Reply With Quote
Old 06-18-2011, 08:22 PM   #2
Fully Optimized
 
strollin's Avatar
 
Join Date: Mar 2011
Location: USA
Posts: 1,943
Default Re: I need C++ help.

Your program as written won't work for several reasons. First of all, cin.get(); will only pull one character from the input buffer and you didn't assign it to any variable so it is being thrown away. You need to do something like cin >> number1; to get a number assigned to the variable number1, cin >> number2; to get a number into number2 and so forth. Your If test won't work as written either, for one thing to test equality you need to use ==, not =.

Her's a link to a sample C++ calculator that may give you some ideas for your own calculator program: C++ calculator - C++ - Source Code | DreamInCode.net
__________________

strollin is offline   Reply With Quote
Old 06-18-2011, 09:51 PM   #3
Baseband Member
 
Join Date: Jun 2011
Posts: 30
Default Re: I need C++ help.

I changed this but it's still not working.
Code:
#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
    cout << "This is my calculator. It follows the BEDMAS Rules. \n" ;
    int number1 ;
    int number2 ;
    int number3 ;

    int finalequation ;

    cout << "Enter two or three numbers. \n" ;
    cout << "Use * to multiply. \n" ;
    cout << "Use + to add. \n" ;
    cout << "Use - to subtract. \n" ;
    cout << "Use / to divide. \n" ;
    
    cin >> number1 + number2 + number3 = finalequation ;
    cout << "You just added"; cout << number1; cout << " to "; cout << number2; cout << "to"; cout << number3; cout << "!";

    return 0;
}
JacobP is offline   Reply With Quote
Old 06-18-2011, 11:14 PM   #4
Site Team
 
celegorm's Avatar
 
Join Date: Sep 2006
Posts: 10,713
Send a message via AIM to celegorm
Default Re: I need C++ help.

You need to break up the cin to multiple statements. I'd actually be surprised if it compiled as written. It should look something like this:
Code:
cin >> number1;
cin >> number2;
cin >> number3;
finalequation  = number1 + number2 + number3;
__________________
"as a fanboy i refuse to admit it and will pull countless things out of my butt to disprove it"

Team Thelegorm! Total Kills: 21 (i iz in uor profile, editsing your sigz)
celegorm is offline   Reply With Quote
Old 06-19-2011, 10:40 AM   #5
Baseband Member
 
Join Date: Jun 2011
Posts: 30
Default Re: I need C++ help.

Quote:
Originally Posted by celegorm View Post
You need to break up the cin to multiple statements. I'd actually be surprised if it compiled as written. It should look something like this:
Code:
cin >> number1;
cin >> number2;
cin >> number3;
finalequation  = number1 + number2 + number3;
I see, thank you very much. +reped.

Also, does this have to be an if statement?
JacobP is offline   Reply With Quote
Old 06-19-2011, 02:56 PM   #6
Site Team
 
celegorm's Avatar
 
Join Date: Sep 2006
Posts: 10,713
Send a message via AIM to celegorm
Default Re: I need C++ help.

Nope, you shouldn't need one if you just want to print the results.
__________________
"as a fanboy i refuse to admit it and will pull countless things out of my butt to disprove it"

Team Thelegorm! Total Kills: 21 (i iz in uor profile, editsing your sigz)
celegorm is offline   Reply With Quote
Old 06-19-2011, 07:19 PM   #7
Fully Optimized
 
strollin's Avatar
 
Join Date: Mar 2011
Location: USA
Posts: 1,943
Default Re: I need C++ help.

If you want to do anything else beside have the user enter 3 numbers which you add then display the result then youo most likely will want to use a switch statement. Did you look at the example calculator that I linked to in my post above?
strollin is offline   Reply With Quote
Old 06-19-2011, 08:12 PM   #8
Baseband Member
 
Join Date: Jun 2011
Posts: 30
Default Re: I need C++ help.

Yea but I can't seem to do this correctly. Can you try and help me from where I am right now?
Code:
#include "stdafx.h"
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    cout << "This is my calculator. It follows the BEDMAS Rules. \n" ;
    int num1 ;
    int num2 ;
    int num3 ;

    int final ;

    cout << "Enter two or three numbers. \n" ;
    cout << "Use * to multiply. \n" ;
    cout << "Use + to add. \n" ;
    cout << "Use - to subtract. \n" ;
    cout << "Use / to divide. \n" ;
    
    cin >> final ;
    cin >> num1 ;
    cin >> num2 ;
    cin >> num3 ;
    while(final == num1 + num2 + num3) ;
    final = num1 + num2 + num3 ;
    cout << "You just added"; cout << num1; cout << " to "; cout << num2; cout << "to"; cout << num3; cout << "!";

    cin.get();
    return 0;
}
JacobP is offline   Reply With Quote
Old 06-19-2011, 08:57 PM   #9
7D8
In Runtime
 
7D8's Avatar
 
Join Date: Oct 2006
Posts: 209
Default Re: I need C++ help.

your while loop isn't looping through anything. Its basically saying:

while final equals num1 plus num2 plus num3 .... and then it terminates. (sorry, don't have a way to test the code right now)
7D8 is offline   Reply With Quote
Old 06-20-2011, 01:56 AM   #10
Fully Optimized
 
strollin's Avatar
 
Join Date: Mar 2011
Location: USA
Posts: 1,943
Default Re: I need C++ help.

Why don't you start by writing what is referred to a pseudo-code, a series of statements describing what you want the program to do before you starting writing the code? You need some kind of a road map to follow. If you were writing a paper you would probably write down an outline, same type of thing.
__________________

strollin is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 02:50 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0