C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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:
  #1  
Old January 21st, 2013, 11:44 AM
blobman23 blobman23 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 16 blobman23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 41 m 15 sec
Reputation Power: 0
I need help with an assignment.

Here is my assignment:

Your task for this assignment is to write a simple calculator that can add, subtract, divide, multiply, and square numbers inputted by the user.

Your program should first ask the user for the first number. The program should then loop, showing the user a menu like this:

Running Total: 0
Please choose one of the following options:
1. Add
2. Subtract
3. Multiply
4. Divide
5. Square
0. Exit the program
Your choice:

The first line of the menu should display the running total, the result of all previous operations.

Your program should take an integer as input. If the user chooses 0, the program should exit.

If the user chooses 1, 2, 3, or 4, the program should ask for a new number and then perform that operation.

If the user chooses 5, the program should multiply the running total by itself and display the new running total and menu.

******************************************

I am having trouble trying to figure out how to do the running total, and also how to do the squaring function so that it will not look to prompt the second number and will just square the running total.

******************************************

Here is my code so far:

Code:
#include <iostream>
using namespace std;

// Program starts in main()
int main()
{
	// Declare Variables:
	double num1;
	double num2;
	int action;
	double result;
	double runningTotal = 0;
	
	do {
		// Get the fisrt number, second number, and operator.
		cout << "Running Total is: " << runningTotal << endl;
		cout << "Enter Your fisrt number: ";
		cin >> num1;
		
		
		cout << "Please choose one of the following options:" << endl
		   	<< "1.Add" << endl
		 	<< "2.Subtract" << endl
		 	<< "3.Multiply" << endl
		 	<< "4.Divide" << endl
		 	<< "5.Square" << endl
		 	<< "0.Exit the program" << endl;
		cout << "Your choice: ";
		cin >> action;
		
		cout << "Enter your second number: ";
		cin >> num2;
		
		
		// Calculations
		
		if (action == 1)
		{
			result = num1 + num2;
		}
		if (action == 2)
		{
			result = num1 - num2;
		}
		if (action == 3)
		{
			result = num1 * num2;
		}
		if (action == 4)
		{
			result = num1 / num2;
		}
		if (action == 5)
		{
			result = runningTotal * runningTotal;
		}
		cout << "Your total is: " << result << endl;
	   } while (action != 0);
	
}

Reply With Quote
  #2  
Old January 21st, 2013, 12:35 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,836 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 16 h 15 m 5 sec
Reputation Power: 1774
I think you need to delete these lines
Code:
		cout << "Enter your second number: ";
		cin >> num2;


And change the calculations to be something like
Code:
		// Calculations
		if (action == 1)
		{
			runningTotal = runningTotal + num1;
		}
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > I need help with an assignment.

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap