Jump to content

Need Help with homework!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
keenbean

keenbean

    Newbie

  • Members
  • Pip
  • 5 posts
Hello, Im almost done with my program, I just need to add a prompt that ask if you want to rerun the program or close it so basically a question that ask the question, "Would you like to rerun or close the program. Please enter R or C."
So I know that the code should be something like cout << Would you like to rerun or close the Progarm? Enter R for rerun, or C for close." <<

#include <fstream>
#include <iostream>

using namespace std;                                    

float number;
const float PI = 3.14159;
float Diameter ( float );
float Circumference ( float );
float Area ( float );

int main ()
{
    float number;
    ifstream inData;
    ofstream outData;
    
    inData.open("lab4.dat");
    outData.open("lab4.out");
    
    int n = 1;
    while (n <= 3)
    {
    inData >> number;                //Radius of the circle
  
    cout << "For the circle with radius: " << number << endl;
    cout << "The Diameter of the Circle is: "<< Diameter( number ) << endl;
    cout << "The Circumference is: "<< Circumference( number ) << endl;
    cout << "The Area is: "<< Area( number ) << endl;
    cout << endl;
    outData << "For the circle with radius: " << number << endl;
    outData << "The Diameter of the Circle is: "<< Diameter( number ) << endl;
    outData << "The Circumference is: "<< Circumference( number ) << endl;
    outData << "The Area is: "<< Area( number ) << endl;
    outData << endl; 
    n++;
    }
   
    inData.close();
    outData.close();
    system ("Pause");
    return 0;
}

float Diameter ( float number )
{
      return 2 * number;
}

float Circumference ( float number )
{
      return PI * number * 2;
}

float Area ( float number )
{
      return PI * number * number;
}

Edited by WingedPanther, 15 December 2009 - 03:00 PM.
add code tags (the # button)


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You'll need a while loop (or a do while loop) around most of your code to get the repetition.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,298 posts
also, you need to do a check on what the answer is, and if it is, rerun the code, otherwise exit. easiest is using a while loop
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#4
keenbean

keenbean

    Newbie

  • Members
  • Pip
  • 5 posts
How exactly would I do that?

#5
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Like this.
char runprogam = 'r'
while(runprogram == 'r')
{

cout << "Do you want to run or close the program again?(r/c);
cin >> runprogram
}if(runprogram != 'r')
cout << "You chose to quit. << endl;
(Some one tell me if I can't post source code for people with homework.)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#6
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,298 posts
We do post code, no worries, as long as we don't do their homework :-)
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#7
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
OK been on some forums were they don't won't you to post code for people with homework.:)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.