Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,398 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,112 people online right now. Registration is fast and FREE... Join Now!




Calculations not displaying

 
Reply to this topicStart new topic

Calculations not displaying

JayM
21 Sep, 2006 - 04:49 PM
Post #1

New D.I.C Head
*

Joined: 21 Sep, 2006
Posts: 3


My Contributions
Hi everyone, new to the board here as well as the language. I am in my first year of learning C++ and my instructor requires we write a program that does a simple calculation. I am getting no errors in my program, however, the parser gets to the last cin >> statement and exits without showing the calculations. Any help would be gladly appreciated.

CODE


#include <iostream>

using namespace std;


  void main(void)
    {
      float wallLength1;
      float wallWidth1;

      float wallLength2;
      float wallWidth2;

      float doorLength;
      float doorWidth;

      float windLength;
      float windWidth;

      const double rollLength = 20;
      const double rollWaste = 0.15;

      float windArea;
      float doorArea;
      float roomArea;
      float newRolls;
      float rollsRequired;

      cout << "Enter the Length of the first wall: ";
      cin >> wallLength1;
      

      cout << "Enter the Width of the first wall: ";
      cin >> wallWidth1;


      cout << "Enter the Length of the second wall: ";
      cin >> wallLength2;

      cout << "Enter the Width of the second wall: ";
      cin >> wallWidth2;
      

      cout << "Enter the Length of the door: ";
      cin >> doorLength;
      

      cout << "Enter the Width of the door: ";
      cin >> doorWidth;

      cout << "Enter the Length of the window: ";
      cin >> windLength;

      cout << "Enter the Width of the window:";
      cin >> windWidth;
      
      windArea = windLength * windWidth;
      
      doorArea = doorLength * doorWidth;
      
      roomArea = ((wallLength1 * wallWidth1) + (wallLength2 * wallWidth2)) * 2;
      
      newRolls = rollLength - (rollLength * rollWaste);
      
      cout << "The amount of rolls required is ";
      rollsRequired = ((roomArea - windArea - doorArea)/newRolls);      

      return;
    }

User is offlineProfile CardPM
+Quote Post

Xing
RE: Calculations Not Displaying
21 Sep, 2006 - 05:03 PM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
Check This
CODE
rollsRequired = ((roomArea - windArea - doorArea)/newRolls);
cout << "The amount of rolls required is "<<rollsRequired;

User is offlineProfile CardPM
+Quote Post

JayM
RE: Calculations Not Displaying
21 Sep, 2006 - 05:07 PM
Post #3

New D.I.C Head
*

Joined: 21 Sep, 2006
Posts: 3


My Contributions
No luck. That didn't work. Once I enter windWidth the window closes. Any more ideas? Thanks
User is offlineProfile CardPM
+Quote Post

JayM
RE: Calculations Not Displaying
21 Sep, 2006 - 05:17 PM
Post #4

New D.I.C Head
*

Joined: 21 Sep, 2006
Posts: 3


My Contributions
QUOTE(JayM @ 21 Sep, 2006 - 06:07 PM) *

No luck. That didn't work. Once I enter windWidth the window closes. Any more ideas? Thanks


I got it working. I changed the double to a float. Thats where my problem was.
Thanks.
User is offlineProfile CardPM
+Quote Post

Xing
RE: Calculations Not Displaying
21 Sep, 2006 - 05:18 PM
Post #5

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
Add a getchar() before return

This post has been edited by Dark_Nexus: 26 Sep, 2006 - 11:07 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 03:03AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month