Results 1 to 14 of 14
  1. #1
    BobFM's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    71
    Reputation
    10
    Thanks
    6
    My Mood
    Inspired

    Angry "Skip" Problem? [Solved]

    So I just started learning C++, and I figured the best way to remember / figure out new things is to practice. So, I was going to build a simple calculator. But I have a problem >_< here's the code so far. And I know it is un-organized, but I was trying to remove spaces and do stupid things to desperately make it work..

    (ONLY _ADD() IS FINISHED)
    Code:
    #include "stdafx.h"
    #include <iostream>
    
    using namespace std;
    
    //Global Variables
    
    	int x;
    	int y;
    	int userAnswerX;
    	int userAnswerY;
    
    	int userChoice;
    
    //Global Variables
    
    int main()
    {
    	cout << "===================\n";
    	cout << "=    Calculator   =\n";
    	cout << "===================\n";
    	cout << "1) Add\n";
    	cout << "2) Subtract\n";
    	cout << "3) Multiply\n";
    	cout << "4) Divide\n";
    	cout << "(Type the number)\n";
    	
    	cin >> userChoice;
    
    		if (userChoice==1) _add();
    
    			if (userChoice==2) _subtract();
    
    				if (userChoice==3) _multiply();
    
    					if (userChoice==4) _divide();
    						
    						else (system("pause>nul"));
    
    }
    
    
    int _add ()
    {
    	cout << "\nEnter value for X: ";
    
    	cin >> userAnswerX;
    
    	x = userAnswerX;
    
    	cout << "\nEnter value for Y: ";
    	
    	cin >> userAnswerY;
    
    	y = userAnswerY;
    
    	cout << "\nYou set X equal to ";
    	cout << x;
    	cout << "\nYou set Y equal to ";
    	cout << y;
    	cout << "\n \n";
    	
    	cout << x + y
    	
    	system("pause>nul");
    }
    
    int _subtract ()
    {
    
    }
    
    int _multiply ()
    {
    
    }
    
    int _divide ()
    {
    
    }
    Here is a SS of what happens when I first build / run:



    Here's what SHOULD happen:

    Code:
    ================
    =  Calculator  =
    ================
    1) Add
    2) Subtract
    3) Multiply
    4) Divide
    (Type the number)
    
    "User types number here"
    ( Goes to _add(), _subtract(), _multiply(), or _divide() )
    Sorry if I wasn't perfectly clear, feel free to ask questions.

    Edit: If you can't see the screen shot, download the attachment.
    Last edited by BobFM; 08-20-2011 at 09:49 AM. Reason: Screen Shot didn't show up
    = Incomplete
    = Learning/trying
    = Completed
    = Owned and stomped!

    Languages:

    DOS/Batch

    HTML/JavaScript



    C++ - (But dedicated. ;D)

  2. #2
    Terell.'s Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    JAMAICAA
    Posts
    6,923
    Reputation
    273
    Thanks
    1,163
    My Mood
    Angry
    Don't post the screenshot as an attachment.. post it like this [img]Your screenshot link[/img] When I see the picture I can assist you a bit more.
    Are you saying that when you run your calculator it doesn't skip lines ?
    Last edited by Terell.; 08-20-2011 at 09:42 AM.

    Warrock Minion 8-13-2011 - N/A
    A.V.A Minion since 11-1-11 - 11-12-11

  3. #3
    BobFM's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    71
    Reputation
    10
    Thanks
    6
    My Mood
    Inspired
    Quote Originally Posted by Shunnai View Post
    Don't post the screenshot as an attachment.. post it like this [img]Your screenshot link[/img] When I see the picture I can assist you a bit more
    I did, it doesn't seem to be working...can I just [URL] it?
    = Incomplete
    = Learning/trying
    = Completed
    = Owned and stomped!

    Languages:

    DOS/Batch

    HTML/JavaScript



    C++ - (But dedicated. ;D)

  4. #4
    Terell.'s Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    JAMAICAA
    Posts
    6,923
    Reputation
    273
    Thanks
    1,163
    My Mood
    Angry
    Sure that'll work.

    Warrock Minion 8-13-2011 - N/A
    A.V.A Minion since 11-1-11 - 11-12-11

  5. #5
    BobFM's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    71
    Reputation
    10
    Thanks
    6
    My Mood
    Inspired
    Photo here

    Quote Originally Posted by Shunnai View Post
    Don't post the screenshot as an attachment.. post it like this [img]Your screenshot link[/img] When I see the picture I can assist you a bit more.
    Are you saying that when you run your calculator it doesn't skip lines ?
    Sorry, didn't realize what else you said. The problem is it IS skipping lines. It skipped everything after ==== Calculator ==== and went strait to _add()

    Photo Here
    Last edited by BobFM; 08-20-2011 at 09:47 AM.
    = Incomplete
    = Learning/trying
    = Completed
    = Owned and stomped!

    Languages:

    DOS/Batch

    HTML/JavaScript



    C++ - (But dedicated. ;D)

  6. #6
    Terell.'s Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    JAMAICAA
    Posts
    6,923
    Reputation
    273
    Thanks
    1,163
    My Mood
    Angry
    So you want

    Code:
    	cout << "===================\n";
    	cout << "1) Add\n";
    	cout << "2) Subtract\n";
    	cout << "3) Multiply\n";
    	cout << "4) Divide\n";
    	cout << "(Type the number)\n";
    to appear before
    Code:
    Enter value for X

    Warrock Minion 8-13-2011 - N/A
    A.V.A Minion since 11-1-11 - 11-12-11

  7. #7
    BobFM's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    71
    Reputation
    10
    Thanks
    6
    My Mood
    Inspired
    Exactly, I'm not even sure how it skipped in the first place...it should prompt the user to enter 1 - 4, then afterwards, I have an array of "IF's", each leading to different functions. Entering anything but 1 - 4 will pause, then exit the program.


    I can't even tell if I made a noob move, I see nothing wrong within the main() function...
    Last edited by BobFM; 08-20-2011 at 09:57 AM.
    = Incomplete
    = Learning/trying
    = Completed
    = Owned and stomped!

    Languages:

    DOS/Batch

    HTML/JavaScript



    C++ - (But dedicated. ;D)

  8. #8
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    [highlight=c]#include <iostream>
    #include <conio.h>
    using std::cout;
    using std::endl;
    using std::cin;
    void Add(int x, int y);
    void Subtract(int x, int y);
    void Multiply(int x, int y);
    void Divide(int x, int y);
    void ExitProgram();
    void main()
    {
    int userChoice;
    int x=0,y=0;
    cout << "===================" << endl;
    cout << "= Calculator =" << endl;
    cout << "===================" << endl;
    cout << "1) Add" << endl;
    cout << "2) Subtract" << endl;
    cout << "3) Multiply" << endl;
    cout << "4) Divide" << endl << endl;
    cout << "Type the Number:" << endl;
    cin >> userChoice;
    if(userChoice < 1 || userChoice > 4)
    {
    cout << "Invalid choice. Press any key to exit." << endl;
    _getch();
    exit(0);
    }
    cout << "Enter Value for X: " << endl;
    cin >> x;
    cout << "Enter Value for Y:" << endl ;
    cin >> y;
    cout << endl;
    switch(userChoice)
    {
    case 1:
    Add(x,y);
    break;
    case 2:
    Subtract(x,y);
    break;
    case 3:
    Multiply(x,y);
    break;
    case 4:
    Divide(x,y);
    break;
    default:
    cout << "Invalid choice. Program will close now." << endl;
    exit(0);
    }
    _getch();
    }
    void ExitProgram()
    {
    cout << endl << "Press any key to exit." << endl;
    _getch();
    exit(0);
    }
    void Add(int x,int y)
    {
    cout << "Result of addition of " << x << " and " << y << " is: " << x+y << endl;
    ExitProgram();
    }
    void Subtract(int x,int y)
    {
    cout << "Result of subtraction of " << x << " and " << y << " is: " << x-y << endl;
    ExitProgram();
    }
    void Multiply(int x,int y)
    {
    cout << "Result of multiplication of " << x << " and " << y << " is: " << x*y << endl;
    ExitProgram();
    }
    void Divide(int x,int y)
    {
    cout << "Result of division of " << x << " and " << y << " is: " << x / y << endl;
    ExitProgram();
    }[/highlight]

    Should Work ;]

  9. The Following User Says Thank You to Hassan For This Useful Post:

    BobFM (08-20-2011)

  10. #9
    Terell.'s Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    JAMAICAA
    Posts
    6,923
    Reputation
    273
    Thanks
    1,163
    My Mood
    Angry
    Quote Originally Posted by Hassan View Post
    [highlight=c]#include <iostream>
    #include <conio.h>
    using std::cout;
    using std::endl;
    using std::cin;
    void Add(int x, int y);
    void Subtract(int x, int y);
    void Multiply(int x, int y);
    void Divide(int x, int y);
    void ExitProgram();
    void main()
    {
    int userChoice;
    int x=0,y=0;
    cout << "===================" << endl;
    cout << "= Calculator =" << endl;
    cout << "===================" << endl;
    cout << "1) Add" << endl;
    cout << "2) Subtract" << endl;
    cout << "3) Multiply" << endl;
    cout << "4) Divide" << endl << endl;
    cout << "Type the Number:" << endl;
    cin >> userChoice;
    if(userChoice < 1 || userChoice > 4)
    {
    cout << "Invalid choice. Press any key to exit." << endl;
    _getch();
    exit(0);
    }
    cout << "Enter Value for X: " << endl;
    cin >> x;
    cout << "Enter Value for Y:" << endl ;
    cin >> y;
    cout << endl;
    switch(userChoice)
    {
    case 1:
    Add(x,y);
    break;
    case 2:
    Subtract(x,y);
    break;
    case 3:
    Multiply(x,y);
    break;
    case 4:
    Divide(x,y);
    break;
    default:
    cout << "Invalid choice. Program will close now." << endl;
    exit(0);
    }
    _getch();
    }
    void ExitProgram()
    {
    cout << endl << "Press any key to exit." << endl;
    _getch();
    exit(0);
    }
    void Add(int x,int y)
    {
    cout << "Result of addition of " << x << " and " << y << " is: " << x+y << endl;
    ExitProgram();
    }
    void Subtract(int x,int y)
    {
    cout << "Result of subtraction of " << x << " and " << y << " is: " << x-y << endl;
    ExitProgram();
    }
    void Multiply(int x,int y)
    {
    cout << "Result of multiplication of " << x << " and " << y << " is: " << x*y << endl;
    ExitProgram();
    }
    void Divide(int x,int y)
    {
    cout << "Result of division of " << x << " and " << y << " is: " << x / y << endl;
    ExitProgram();
    }[/highlight]

    Should Work ;]
    Beat me too it.

    Warrock Minion 8-13-2011 - N/A
    A.V.A Minion since 11-1-11 - 11-12-11

  11. #10
    BobFM's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    71
    Reputation
    10
    Thanks
    6
    My Mood
    Inspired
    Thank you guys. I'm still learning. :'(

    Quote Originally Posted by Shunnai View Post
    Beat me too it.
    He forgot #include "stdafx.h"

    Thank you though.
    Last edited by BobFM; 08-20-2011 at 10:22 AM.
    = Incomplete
    = Learning/trying
    = Completed
    = Owned and stomped!

    Languages:

    DOS/Batch

    HTML/JavaScript



    C++ - (But dedicated. ;D)

  12. #11
    Terell.'s Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    JAMAICAA
    Posts
    6,923
    Reputation
    273
    Thanks
    1,163
    My Mood
    Angry
    Anytime, & if you want some credits at the end do something like

    Code:
    cout<<"yourcalculatorname,Developed  by BobFM\n";
    Code:
    cout << "Copyright© 2011 " << endl;
    Or something in that sort.
    Last edited by Terell.; 08-20-2011 at 10:24 AM.

    Warrock Minion 8-13-2011 - N/A
    A.V.A Minion since 11-1-11 - 11-12-11

  13. The Following User Says Thank You to Terell. For This Useful Post:

    BobFM (08-20-2011)

  14. #12
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by BobFM View Post
    Thank you guys. I'm still learning. :'(



    He forgot #include "stdafx.h"

    Thank you though.
    #include "stdafx.h" wasn't needed here. The program compiles perfectly fine. Anyways, have fun !!

  15. #13
    BobFM's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    71
    Reputation
    10
    Thanks
    6
    My Mood
    Inspired
    Quote Originally Posted by Hassan View Post


    #include "stdafx.h" wasn't needed here. The program compiles perfectly fine. Anyways, have fun !!
    Mine had a fatal error until I added it D: Probably different compiler or something...Dunno, but either way, thanks.
    Last edited by BobFM; 08-20-2011 at 10:34 AM.
    = Incomplete
    = Learning/trying
    = Completed
    = Owned and stomped!

    Languages:

    DOS/Batch

    HTML/JavaScript



    C++ - (But dedicated. ;D)

  16. #14
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Yeah, I guess so. I am using Visual Studio 2010.
    Anyways, Marked Solved.

  17. The Following User Says Thank You to Hassan For This Useful Post:

    BobFM (08-20-2011)

Similar Threads

  1. [Solved] Injector problem solved
    By NinjaKantana in forum CrossFire Help
    Replies: 1
    Last Post: 07-12-2011, 01:40 PM
  2. disconnection problem solved!! fast and easy!
    By raw95 in forum Combat Arms Hacks & Cheats
    Replies: 3
    Last Post: 12-25-2008, 06:09 PM
  3. Disconect Problem solved (maybe).
    By Fairplay? in forum Combat Arms Hacks & Cheats
    Replies: 2
    Last Post: 12-20-2008, 03:52 PM
  4. MPGH Hack Problem Solved!
    By pnus88 in forum Combat Arms Hacks & Cheats
    Replies: 17
    Last Post: 12-19-2008, 11:35 PM
  5. Problem Solved...
    By Dave84311 in forum News & Announcements
    Replies: 0
    Last Post: 04-02-2007, 03:22 PM