baconswife 0 Junior Poster in Training

Wow, shows how much a break statement helps. Thank you!

baconswife 0 Junior Poster in Training

I got it to leave out the one but am still having trouble with the invalid input part

#include <iostream>

using namespace std;

void menuFunction();
void addFrac(int num1, int num2, int den1, int den2, int numres, int demres);
void subtractFraction(int num1, int num2, int den1, int den2, int numres, int demres);
void multiplyFraction(int num1, int num2, int den1, int den2, int numres, int demres);
void divideFraction(int num1, int num2, int den1, int den2, int numres, int demres);
void goodbyeFunction();

int main()
{
	menuFunction();
	cout << ' ' << endl;
	system ("pause");
	return 0;
}

void menuFunction()
{

	int choice, num1, num2, den1, den2, numres = 0, demres = 0;
	while (choice != 9)
	{
		cout<<"This program performs operations on fraction. Enter"<<endl;
		cout<<"1 : To add fraction"<<endl;
		cout<<"2 : To subtract fraction"<<endl;
		cout<<"3 : To multiply fraction"<<endl;
		cout<<"4 : To divide fraction"<<endl;
		cout<<"9 : To exit the program"<<endl;
		cin >> choice;
		if (choice != 9)
		{
			cout <<"For fraction 1" << endl;
			cout << "Enter the numerator: " << endl;
			cin >> num1;
			cout<<" " << endl;
			cout << "Enter the denominator: " << endl;
			cin >> den1;
			cout<<" " << endl;
			cout<<" " << endl;
			cout <<"For fraction 2" << endl;
			cout << "Enter the numerator: " << endl;
			cin >> num2;
			cout<<" " << endl;
			cout << "Enter the denominator: " <<  endl;
			cin >> den2;
		}

		switch(choice)
		{
		case 1:
			addFrac(num1, num2, den1, den2, numres, demres);
			break;
		case 2:
			subtractFraction(num1, num2, den1, den2, numres, demres);
			break;
		case …
baconswife 0 Junior Poster in Training

Fixed my indentation but for some reason still having trouble figuring out where I'm wrong. I think it may be because I have been staring at it for so long

#include <iostream>

using namespace std;

void menuFunction();
void addFrac(int num1, int num2, int den1, int den2, int numres, int demres);
void subtractFraction(int num1, int num2, int den1, int den2, int numres, int demres);
void multiplyFraction(int num1, int num2, int den1, int den2, int numres, int demres);
void divideFraction(int num1, int num2, int den1, int den2, int numres, int demres);
void goodbyeFunction();

int main()
{
	menuFunction();
	cout << ' ' << endl;
	system ("pause");
	return 0;
}

void menuFunction()
{

	int choice, num1, num2, den1, den2, numres = 0, demres = 0;
	while (choice != 9)
	{
		cout<<"This program performs operations on fraction. Enter"<<endl;
		cout<<"1 : To add fraction"<<endl;
		cout<<"2 : To subtract fraction"<<endl;
		cout<<"3 : To multiply fraction"<<endl;
		cout<<"4 : To divide fraction"<<endl;
		cout<<"9 : To exit the program"<<endl;
		cin >> choice;
		if (choice != 9)
		{
			cout <<"For fraction 1" << endl;
			cout << "Enter the numerator: " << endl;
			cin >> num1;
			cout<<" " << endl;
			cout << "Enter the denominator: " << endl;
			cin >> den1;
			cout<<" " << endl;
			cout<<" " << endl;
			cout <<"For fraction 2" << endl;
			cout << "Enter the numerator: " << endl;
			cin >> num2;
			cout<<" " << endl;
			cout << "Enter the denominator: " <<  endl;
			cin >> den2;
		}
		else 
			cout << "Goodbye." << endl;
		switch(choice)
		{
		case …
baconswife 0 Junior Poster in Training

I fixed it some what but am still having 2 problems. When I put 9 it outputs goodbye as it should but it also outputs 1 right under goodbye and then under that outputs invalid input. The other problem is that you can type 5 or any other number and it will still run through rather than just saying invalid input

#include <iostream>

using namespace std;

void menuFunction();
void addFrac(int num1, int num2, int den1, int den2, int numres, int demres);
void subtractFraction(int num1, int num2, int den1, int den2, int numres, int demres);
void multiplyFraction(int num1, int num2, int den1, int den2, int numres, int demres);
void divideFraction(int num1, int num2, int den1, int den2, int numres, int demres);
void goodbyeFunction();

int main()
{
	menuFunction();
    cout << ' ' << endl;
    system ("pause");
	return 0;
}

void menuFunction()
{
     
	int choice, num1, num2, den1, den2, numres = 0, demres = 0;
		while (choice != 9)
	{
	cout<<"This program performs operations on fraction. Enter"<<endl;
	cout<<"1 : To add fraction"<<endl;
	cout<<"2 : To subtract fraction"<<endl;
	cout<<"3 : To multiply fraction"<<endl;
	cout<<"4 : To divide fraction"<<endl;
	cout<<"9 : To exit the program"<<endl;
	cin >> choice;
	if (choice != 9)
	{
	cout <<"For fraction 1" << endl;
	cout << "Enter the numerator: " << endl;
    cin >> num1;
	cout<<" " << endl;
	cout << "Enter the denominator: " << endl;
	cin >> den1;
	cout<<" " << endl;
	cout<<" " << endl;
    cout <<"For fraction 2" << endl;
    cout << "Enter the numerator: …
baconswife 0 Junior Poster in Training

Hello, for some reason I am having trouble remembering how to make it exit when they push the number 9. Can anyone help me? Also, I need it to repeat rather than at the end saying "press any key to continue" I know I will do this using while (choice != 9) but am not sure where I should place it in the program. If anyone has any ideas please let me know.

#include <iostream>

using namespace std;

void menuFunction();
void addFrac(int num1, int num2, int den1, int den2, int numres, int demres);
void subtractFraction(int num1, int num2, int den1, int den2, int numres, int demres);
void multiplyFraction(int num1, int num2, int den1, int den2, int numres, int demres);
void divideFraction(int num1, int num2, int den1, int den2, int numres, int demres);
void exit();

int main()
{
	menuFunction();
    cout << ' ' << endl;
    system ("pause");
	return 0;
}

void menuFunction()
{
	int choice, num1, num2, den1, den2, numres = 0, demres = 0;
	cout<<"This program performs operations on fraction. Enter"<<endl;
	cout<<"1 : To add fraction"<<endl;
	cout<<"2 : To subtract fraction"<<endl;
	cout<<"3 : To multiply fraction"<<endl;
	cout<<"4 : To divide fraction"<<endl;
	cout<<"9 : To exit the program"<<endl;
	cin >> choice;
	cout <<"For fraction 1" << endl;
	cout << "Enter the numerator: " << endl;
    cin >> num1;
	cout<<" " << endl;
	cout << "Enter the denominator: " << endl;
	cin >> den1;
	cout<<" " << endl;
	cout<<" " << endl;
    cout <<"For fraction 2" << endl;
    cout << "Enter …
baconswife 0 Junior Poster in Training

I'm not sure how to put it. I have gotten this far but am missing some stuff. I'm mostly concerned about the first one, once I do that I can do the other 2.

#include <iostream>
#include <iomanip>

using namespace std;

void defaultParam(int u, int v = 5, double z = 3.2);

int main()
{
    defaultParam(6);
    cout << defaultParam << endl;
    system ("pause");
    
    return 0;
}

void defaultParam(int u, int v = 5, double z = 3.2)
{
     int a;
     u = u + static_cast<int>(2 * v + z);
     a = u + v * z;
     cout << "a = " << a << endl;
}
baconswife 0 Junior Poster in Training

Can someone help me on this?
While considering the following function definition:

void defaultParam(int u, int v = 5, double z = 3.2)
{
     int a;
     u = u + static_cast<int>(2 * v + z);
     a = u + v * z;
     cout << "a = " << a << endl;
}

What does the following output
a)

defaultParam(6);

b)

defaultParam(3,4);

c)

defaultParam(3, 0, 2.8);

I got a) 35 b)28.8 c) 24.96. Is that anywhere close?

baconswife 0 Junior Poster in Training

It will run now but when I open the output file it outputs: Number of female students = 12
Average female GPA = 206323346029811400000000000.00
Number of male students = 14
Average male GPA = 0.29
any ideas on why it may be doing this? The avg female gpa should be around 3.36 and there are 14 female students & 14 male students. I haven't calculated what male gpa really should be yet.

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
void OpenFiles(ifstream& inFile, ofstream& outFile);
void initialize(int& countFemale, int& countMale, float& sumFemGPA, float& sumMaleGPA);
void sumGrades(int& countFemale, int& countMale, float& sumMaleGPA, float& sumFemGPA, ifstream& inFile, ofstream& outFile, char ch, double gpa);
void averageGrades(int& countFemale, int& countMale, float& sumFemGPA, float& sumMaleGPA, float& avgFemGPA, float& avgMaleGPA);
void printResults(ifstream& inFile, ofstream& outFile, int& countFemale, int& countMale, float& avgMaleGPA, float& avgFemGPA, float& sumMaleGPA, float& sumFemGPA);

int main ()
{
    ifstream inFile;
    ofstream outFile;
    char ch;
    float gpa;
    float avgFemGPA, avgMaleGPA;
    int countFemale, countMale;
    float FemGPA, MaleGPA, sumFemGPA, sumMaleGPA;

initialize(countFemale, countMale, sumFemGPA, sumMaleGPA);

OpenFiles(inFile, outFile);

while(!inFile.eof())
    {
        sumGrades(countFemale, countMale, sumMaleGPA, sumFemGPA, inFile, outFile, ch, gpa);
        averageGrades(countFemale, countMale, sumMaleGPA, sumFemGPA, avgFemGPA, avgMaleGPA);
        inFile >> ch >> gpa;
    }
  cout << "Processing grades" << endl;
  cout << "Output data is in file Ch7_Ex4Out.txt" << endl;

    printResults(inFile, outFile, countFemale, countMale, avgMaleGPA, avgFemGPA, sumMaleGPA, sumFemGPA);
    inFile.close();
    outFile.close();
    system ("pause");

return 0;
}

void OpenFiles(ifstream& inFile, ofstream& outFile)
{
    char ch;
    double gpa;
    inFile;
    outFile;
    inFile.open ("Ch7_Ex4Data.txt");
    outFile.open ("Ch7_Ex4Out.txt");
    if(!inFile)
    {
        cout << "Cannot …
baconswife 0 Junior Poster in Training

It runs but nothing appears correctly in the output file.

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
void OpenFiles(char ch, float gpa);
void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA);
void sumGrades(int countFemale, int countMale, float sumMaleGPA, float sumFemGPA);
void averageGrades(float avgFemGPA, float avgMaleGPA);
void printResults(int countFemale, int countMale, float avgMaleGPA, float avgFemGPA, float sumMaleGPA, float sumFemGPA);

int main ()
{
    ifstream inFile;
    ofstream outFile;
    char ch;
    float gpa;
    float avgFemGPA, avgMaleGPA;
    int countFemale, countMale;
    float FemGPA, MaleGPA, sumFemGPA, sumMaleGPA;

initialize(countFemale, countMale, sumFemGPA, sumMaleGPA);

OpenFiles(ch, gpa);

while(!inFile.eof())
    {
        sumGrades(countFemale, countMale, sumMaleGPA, sumFemGPA);
        averageGrades(avgFemGPA, avgMaleGPA);
        inFile >> ch >> gpa;
    }
  cout << "Processing grades" << endl;
  cout << "Output data is in file Ch7_Ex4Data.txt" << endl;

    printResults(countFemale, countMale, avgMaleGPA, avgFemGPA, sumMaleGPA, sumFemGPA);
    inFile.close();
    outFile.close();
    system ("pause");

return 0;
}

void OpenFiles(char ch, float gpa)
{
    ifstream inFile;
    ofstream outFile;
    inFile.open ("Ch7_Ex4Data.txt");
    outFile.open ("Ch7_Ex4Out.txt");
    if(!inFile)
    {
        cout << "Cannot open input file." << endl;
    }
    inFile.get(ch);
    inFile >> gpa;
    inFile.eof();

    outFile << fixed << showpoint;
    outFile << setprecision(2);
}

void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA)

{
    float FemGPA = 0.0;
    float MaleGPA = 0.0;
    countFemale = 0;
    countMale = 0;
}

void sumGrades(int countFem, int countMale, float sumMaleGPA, float sumFemGPA)
{
    char ch;
    float gpa;
    OpenFiles(ch, gpa);
    float MaleGPA, avgMaleGPA, FemGPA, avgFemGPA;
    switch (ch)
    {
        case 'M':
        case 'm': MaleGPA = MaleGPA + gpa;
        countMale++;
        avgMaleGPA = MaleGPA / countMale;
        break;
        case 'F':
        case 'f': FemGPA = FemGPA + gpa;
        countFem++;
        avgFemGPA = FemGPA …
baconswife 0 Junior Poster in Training

Oh duh. That was dumb of me. Here is the modified code. Hope I didn't screw up this time.

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
void OpenFiles(char ch, float gpa);
void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA);
void sumGrades(int countFemale, int countMale, float sumMaleGPA, float sumFemGPA);
void averageGrades(float avgFemGPA, float avgMaleGPA);
void printResults(int countFemale, int countMale, float avgMaleGPA, float avgFemGPA, float sumMaleGPA, float sumFemGPA);

int main ()
{
    ifstream inFile;
    ofstream outFile;
    char ch;
    float gpa;
    float avgFemGPA, avgMaleGPA;
    int countFemale, countMale;
    float FemGPA, MaleGPA, sumFemGPA, sumMaleGPA;

initialize(countFemale, countMale, sumFemGPA, sumMaleGPA);

OpenFiles(ch, gpa);

while(!inFile.eof())
    {
        sumGrades(countFemale, countMale, sumMaleGPA, sumFemGPA);
        averageGrades(avgFemGPA, avgMaleGPA);
        inFile >> ch >> gpa;
    }
  cout << "Processing grades" << endl;
  cout << "Output data is in file Ch7_Ex4Data.txt" << endl;

printResults(countFemale, countMale, avgMaleGPA, avgFemGPA, sumMaleGPA, sumFemGPA);
inFile.close();
outFile.close();
system ("pause");

return 0;
}

void OpenFiles(char ch, float gpa)
{
    ifstream inFile;
    ofstream outFile;
    inFile.open ("Ch7_Ex4Data.txt");
    outFile.open ("Ch7_Ex4Out.txt");
    if(!inFile)
    {
        cout << "Cannot open input file." << endl;
    }
    inFile.get(ch);
    inFile >> gpa;
    inFile.eof();

    outFile << fixed << showpoint;
    outFile << setprecision(2);
}

void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA)

{
    float FemGPA = 0.0;
    float MaleGPA = 0.0;
    countFemale = 0;
    countMale = 0;
}

void sumGrades(int countFem, int countMale, float sumMaleGPA, float sumFemGPA)
{
    char ch;
    float gpa;
    OpenFiles(ch, gpa);
    float MaleGPA, avgMaleGPA, FemGPA, avgFemGPA;
    switch (ch)
    {
        case 'M':
        case 'm': MaleGPA = MaleGPA + gpa;
        countMale++;
        avgMaleGPA = MaleGPA / countMale;
        break;
        case 'F':
        case 'f': …
baconswife 0 Junior Poster in Training

So wasn't how I was doing it the GNU form?---
This code is from the prettyprint page on wikipedia

int
foo (int k)
{
  if (k < 1 || k > 2)
    {
      printf ("out of range\n");
      printf ("this function requires a value of 1 or 2\n");
    }
  else
    {
      printf ("Switching\n");
      switch (k)
	{
	case 1:
	  printf ("1\n");
	  break;
	case 2:
	  printf ("2\n");
	  break;
	}
    }
}
baconswife 0 Junior Poster in Training

I'm not trying to be a pain but I truly am confused. Per what I read (could have read it wrong) in the tutorial that was posted on this thread for the curly bracket "{" I have to indent it if it follows another curly bracket that hasn't had a closing bracket yet. Please guide me in the correct way to do it and why if I am wrong. For example

{Opening bracket one
stuff in between

    {Opening bracket two
        more stuff
    }Closing bracket for opening bracket two
} Closing bracket for opening bracket one
baconswife 0 Junior Poster in Training

Group256 From my understanding of it I believe that this is the correct way on the indentation. Please correct me if I am wrong (I reformatted it).

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
void OpenFiles(char ch, float gpa);
void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA);
void sumGrades(int countFemale, int countMale, float sumMaleGPA, float sumFemGPA);
void averageGrades(float avgFemGPA, float avgMaleGPA);
void printResults(int countFemale, int countMale, float avgMaleGPA, float avgFemGPA, float sumMaleGPA, float sumFemGPA);

int main ()
{
ifstream inFile;
ofstream outFile;
char ch;
float gpa;
float avgFemGPA, avgMaleGPA;
int countFemale, countMale;
float FemGPA, MaleGPA, sumFemGPA, sumMaleGPA;

initialize(countFemale, countMale, sumFemGPA, sumMaleGPA);

OpenFiles(ch, gpa);

while(!inFile.eof())
    {
        sumGrades(countFemale, countMale, sumMaleGPA, sumFemGPA);
        averageGrades(avgFemGPA, avgMaleGPA);
        inFile >> ch >> gpa;
    }
  cout << "Processing grades" << endl;
  cout << "Output data is in file Ch7_Ex4Data.txt" << endl;

printResults(countFemale, countMale, avgMaleGPA, avgFemGPA, sumMaleGPA, sumFemGPA);
inFile.close();
outFile.close();
system ("pause");

return 0;
}

void OpenFiles(char ch, float gpa)
{
ifstream inFile;
ofstream outFile;
inFile.open ("Ch7_Ex4Data.txt");
outFile.open ("Ch7_Ex4Out.txt");
if(!inFile)
    {
        cout << "Cannot open input file." << endl;
    }
inFile.get(ch);
inFile >> gpa;
inFile.eof();

outFile << fixed << showpoint;
outFile << setprecision(2);
}

void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA)

{
float FemGPA = 0.0;
float MaleGPA = 0.0;
countFemale = 0;
countMale = 0;
}

void sumGrades(int countFem, int countMale, float sumMaleGPA, float sumFemGPA)
{
char ch;
float gpa;
OpenFiles(ch, gpa);
float MaleGPA, avgMaleGPA, FemGPA, avgFemGPA;
switch (ch)
    {
        case 'M':
        case 'm': MaleGPA = MaleGPA + gpa;
        countMale++;
        avgMaleGPA = …
baconswife 0 Junior Poster in Training

Not sure how to quote here so I will just copy and paste
"Here's the deal. I've been programming for over 30 years. Formatting is ultra important. I don't give a rats what you think about it. If you don't start formatting from the first line of code written to the last, you are not a programmer. Period.

I'm done here. You can't follow instructions, I can't help." Mainly the I'm done here part. Unfortunately since no one else was helping I decided to go to someone who does programming on a daily basis and the help I got was something you consider questionable. Sorry you don't agree but I tried.

baconswife 0 Junior Poster in Training

Oh and if this formatting isn't correct than I don't know what. I sat down with someone who is a programmer and they helped me with this. I had something else originally (besides what I posted here) and was told by this person who has been programming for 30+ years, what I had done was wrong and they helped me get to this.

baconswife 0 Junior Poster in Training

I fixed it long ago but wasn't going to bother with posting it if I wasn't getting help. I have fixed a lot with it but am still struggling to have it actually output to the output file and am struggling a bit with the concept of pass by reference.

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
void OpenFiles(char ch, float gpa);
void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA);
void sumGrades(int countFemale, int countMale, float sumMaleGPA, float sumFemGPA);
void averageGrades(float avgFemGPA, float avgMaleGPA);
void printResults(int countFemale, int countMale, float avgMaleGPA, float avgFemGPA, float sumMaleGPA, float sumFemGPA);

int main ()
{
ifstream inFile;
ofstream outFile;
char ch;
float gpa;
float avgFemGPA, avgMaleGPA;
int countFemale, countMale;
float FemGPA, MaleGPA, sumFemGPA, sumMaleGPA;

initialize(countFemale, countMale, sumFemGPA, sumMaleGPA);

OpenFiles(ch, gpa);

while(!inFile.eof())
{
sumGrades(countFemale, countMale, sumMaleGPA, sumFemGPA);
averageGrades(avgFemGPA, avgMaleGPA);
inFile >> ch >> gpa;
}
cout << "Processing grades" << endl;
cout << "Output data is in file Ch7_Ex4Data.txt" << endl;

printResults(countFemale, countMale, avgMaleGPA, avgFemGPA, sumMaleGPA, sumFemGPA);
inFile.close();
outFile.close();
system ("pause");

return 0;
}

void OpenFiles(char ch, float gpa)
{
ifstream inFile;
ofstream outFile;
inFile.open ("Ch7_Ex4Data.txt");
outFile.open ("Ch7_Ex4Out.txt");
if(!inFile)
{
cout << "Cannot open input file." << endl;
}
inFile.get(ch);
inFile >> gpa;
inFile.eof();

outFile << fixed << showpoint;
outFile << setprecision(2);
}

void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA)

{
float FemGPA = 0.0;
float MaleGPA = 0.0;
countFemale = 0;
countMale = 0;
}

void sumGrades(int countFem, int countMale, float sumMaleGPA, float sumFemGPA)
{
char ch;
float …
baconswife 0 Junior Poster in Training

I think I may have fixed some of the problem but need further guidance

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
void OpenFiles(char ch, float gpa);
void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA);
void sumGrades(int countFemale, int countMale, float sumMaleGPA, float sumFemGPA);
void averageGrades(float avgFemGPA, float avgMaleGPA);
void printResult(int countFemale, int countMale, float avgMaleGPA, float avgFemGPA, float sumMaleGPA, float sumFemGPA);

int main ()
{
    ifstream inFile;
    ofstream outFile;
    char ch;
    float gpa;
    float avgFemGPA, avgMaleGPA;
    int countFemale, countMale;
    float FemGPA, MaleGPA, sumFemGPA, sumMaleGPA;
    
    initialize(countFemale, countMale, sumFemGPA, sumMaleGPA);
    
    OpenFiles(ch, gpa);
    
    while(!inFile.eof())
    {
       sumGrades(countFemale, countMale, sumMaleGPA, sumFemGPA);
       averageGrades(avgFemGPA, avgMaleGPA);
       inFile >> ch >> gpa;   
    }
     
     printResult(countFemale, countMale, avgMaleGPA, avgFemGPA, sumMaleGPA, sumFemGPA);


     void OpenFiles(char ch, float gpa);
        {
             ifstream inFile;
             ofstream outFile;
             inFile.open ("Ch7_Ex4Data.txt");
             outFile.open ("Ch7_Ex4Out.txt");
             if(!inFile)
            {
                 cout << "Cannot open input file." << endl;
            }
             inFile.get(ch);
             inFile >> gpa;
             inFile.eof();

             outFile << fixed << showpoint;
             outFile << setprecision(2);
        }

      void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA);

               {
               float FemGPA = 0.0;
               float MaleGPA = 0.0;
               countFemale = 0;
               countMale = 0;
               }

      void sumGrades(int countFem, int countMale, float sumMaleGPA, float sumFemGPA);
                    {
                        char ch;
                        float gpa;
                        OpenFiles(ch, gpa);
                        float MaleGPA, avgMaleGPA;
                        switch (ch)
                        {
                             case 'M':
                             case 'm': MaleGPA = MaleGPA + gpa;
                             countMale++;
                             avgMaleGPA = MaleGPA / countMale;
                             break;
                             case 'F':
                             case 'f': FemGPA = FemGPA + gpa;
                             countFem++;
                             avgFemGPA = FemGPA / countFem;
                             break;
                             default: cout << "Invalid Gender" << endl;
                        }
                    }
     void averageGrades(float avgFemGPA, float avgMaleGPA);
                              {
     
                                  float FemGPA, MaleGPA; …
baconswife 0 Junior Poster in Training

And I would agree with the wasting time part had I spent the last 7 hours doing the program, only problem is I haven't been able to spend more than 5 min on it at a time. I have actually been spending about 30 seconds to do one thing at a time every 10 min or so as I work 50-60 hours a week and am in the middle of doing housework so I have been doing it one tiny modification at a time. And unfortunately still can't see where I am going wrong. I obviously know something is wrong I just am having trouble finding what. Maybe it's because I have looked at it for so long that I am overlooking it, I'm not sure.

baconswife 0 Junior Poster in Training

Not all the formatting has been fixed yet but I am more worried about solving the errors and will worry about perfecting it later.

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
void OpenFiles(char ch, float gpa);
void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA);
void sumGrades(int countFemale, int countMale, float sumMaleGPA, float sumFemGPA);
void averageGrades(float avgFemGPA, float avgMaleGPA);
void printResult(int countFemale, int countMale, float avgMaleGPA, float avgFemGPA, float sumMaleGPA, float sumFemGPA);

int main ()
{
    ifstream inFile;
    ofstream outFile;
    char ch;
    float gpa;
    float avgFemGPA, avgMaleGPA;
    int countFemale, countMale;
    float FemGPA, MaleGPA, sumFemGPA, sumMaleGPA;
    
    initialize(countFemale, countMale, sumFemGPA, sumMaleGPA);
    
    OpenFiles(ch, gpa);
    
    while(!inFile.eof())
    {
       sumGrades(countFemale, countMale, sumMaleGPA, sumFemGPA);
       averageGrades(avgFemGPA, avgMaleGPA);
       inFile >> ch >> gpa;    
    }
     
     printResult(countFemale, countMale, avgMaleGPA, avgFemGPA, sumMaleGPA, sumFemGPA);


     void OpenFiles(char ch, float gpa)
        {
             ifstream inFile;
             ofstream outFile;
             inFile.open ("Ch7_Ex4Data.txt");
             outFile.open ("Ch7_Ex4Out.txt");
             if(!inFile)
            {
                 cout << "Cannot open input file." << endl;
            }
             inFile.get(ch);
             inFile >> gpa;
             inFile.eof();

             outFile << fixed << showpoint;
             outFile << setprecision(2);
        }

      void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA)

               {
               float FemGPA = 0.0;
               float MaleGPA = 0.0;
               countFemale = 0;
               countMale = 0;
               }

      void sumGrades(int countFem, int countMale, float sumMaleGPA, float sumFemGPA)
                    {
                        char ch;
                        float gpa;
                        OpenFiles(ch, gpa);
                        float MaleGPA, FemGPA, avgMaleGPA, avgFemGPA;
                        switch (ch)
                        {
                             case 'M':
                             case 'm': MaleGPA = MaleGPA + gpa;
                             countMale++;
                             avgMaleGPA = MaleGPA / countMale;
                             break;
                             case 'F':
                             case 'f': FemGPA = FemGPA + gpa;
                             countFem++;
                             avgFemGPA = FemGPA / countFem;
                             break;
                             default: cout << "Invalid Gender" << …
baconswife 0 Junior Poster in Training

The only thing I can find at that link that hasn't been done in my program yet is the indentation of { and } and the separate indentations. I have read it twice and don't feel that it is such a huge issue that I have to fix that before the other errors as I am reformatting some of the things later anyways once I get it to fully compile

baconswife 0 Junior Poster in Training
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
void OpenFiles(char ch, float gpa);
void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA);
void sumGrades(int countFemale, int countMale, float sumMaleGPA, float sumFemGPA);
void averageGrades(float avgFemGPA, float avgMaleGPA);
void printResult(int countFemale, int countMale, float avgMaleGPA, float avgFemGPA, float sumMaleGPA, float sumFemGPA);

int main ()
{
    ifstream inFile;
    ofstream outFile;
    char ch;
    float gpa;
    float avgFemGPA, avgMaleGPA;
    int countFemale, countMale;
    float FemGPA, MaleGPA, sumFemGPA, sumMaleGPA;
    
    initialize(countFemale, countMale, sumFemGPA, sumMaleGPA);
    
    OpenFiles(ch, gpa);
    
    while(!inFile.eof())
    {
     sumGrades(countFemale, countMale, sumMaleGPA, sumFemGPA);
     averageGrades(avgFemGPA, avgMaleGPA);
     inFile >> ch >> gpa;    
     }
     
     printResult(countFemale, countMale, avgMaleGPA, avgFemGPA, sumMaleGPA, sumFemGPA);
     }

     void OpenFiles(char ch, float gpa)
     {
     ifstream inFile;
     ofstream outFile;
    inFile.open ("Ch7_Ex4Data.txt");
    outFile.open ("Ch7_Ex4Out.txt");
if(!inFile)
{
           cout << "Cannot open input file." << endl;
}
inFile.get(ch);
inFile >> gpa;
inFile.eof();

outFile << fixed << showpoint;
    outFile << setprecision(2);
}

void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA)

     {
float FemGPA = 0.0;
float MaleGPA = 0.0;
countFemale = 0;
countMale = 0;
     }

void sumGrades(int countFem, int countMale, float sumMaleGPA, float sumFemGPA)
     {
     char ch;
     float gpa;
     OpenFiles(ch, gpa);
     float MaleGPA, FemGPA, avgMaleGPA, avgFemGPA;
     switch (ch)
     {
     case 'M':
     case 'm': MaleGPA = MaleGPA + gpa;
     countMale++;
     avgMaleGPA = MaleGPA / countMale;
     break;
     case 'F':
     case 'f': FemGPA = FemGPA + gpa;
     countFem++;
     avgFemGPA = FemGPA / countFem;
     break;
     default: cout << "Invalid Gender" << endl;
     }
     }
     void averageGrades(float avgFemGPA, float avgMaleGPA)
     {
     
     float FemGPA, MaleGPA;
     int countFem, countMale;
     float sumMaleGPA, sumFemGPA;
     sumGrades (countFem, countMale, sumMaleGPA, sumFemGPA); …
baconswife 0 Junior Poster in Training

I have fixed most of my errors. The only ones I am having now are:where it says inFile.close(); the error is "expected ',' or ';' before '.' token, expected constructor, destructor, or type conversion before '.' token" and then that also appears where outFile.close(); is. Where system ("pause"); is it states "expected constructor, destructor, or type conversion before '(' token, expected ',' or ';' before '(' token. Expected unqalified-id before "return", expected ',' or ';' before "retrun" and the final is expected declaration before '}' token

void printResults(int countFem, int countMale, float avgFemGPA, float avgMaleGPA)
     {
          ofstream outFile;
          outFile << "Number of female students = " << countFem << endl;
          outFile << "Average female GPA = " << avgFemGPA << endl;
          outFile << "Number of male students = " << countMale << endl;
          outFile << "Average male GPA = " << avgMaleGPA << endl;
     }
inFile.close();
outFile.close();
system ("pause");

return 0;
     }
baconswife 0 Junior Poster in Training

Yes, I do realize that I was having trouble finding where it was done.

baconswife 0 Junior Poster in Training

I have resolved a number of my errors and I know that I either have an extra { or } somewhere or put it the wrong way (or at least that's what I think) but I'm not sure where and was hoping maybe someone could look over it because I think I keep grazing over it. The errors I am getting are: line 36 a function definition is not allowed her before '{'
line 36 expected ',' or ';' before '{' token
line 55 a function definition is not allowed her before '{'
line 55 expected ',' or ';' before '{' token
line 63 a function definition is not allowed her before '{'
line 63 expected ',' or ';' before '{' token
line 108 expected '}' at end of input

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
void OpenFiles(char ch, float gpa);
void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA);
void sumGrades(int countFemale, int countMale, float sumMaleGPA, float sumFemGPA);
void averageGrades(float avgFemGPA, float avgMaleGPA);
void printResult(int countFemale, int countMale, float avgMaleGPA, float avgFemGPA, float sumMaleGPA, float sumFemGPA);

int main ()
{
    ifstream inFile;
    ofstream outFile;
    char ch;
    float gpa;
    float avgFemGPA, avgMaleGPA;
    int countFemale, countMale;
    float FemGPA, MaleGPA, sumFemGPA, sumMaleGPA;
    
    initialize(countFemale, countMale, sumFemGPA, sumMaleGPA);
    
    OpenFiles(ch, gpa);
    
    while(!inFile.eof())
    {
     sumGrades(countFemale, countMale, sumMaleGPA, sumFemGPA);
     inFile >> ch >> gpa;
     averageGrades(avgFemGPA, avgMaleGPA);
     }
     
     printResult(countFemale, countMale, avgMaleGPA, avgFemGPA, sumMaleGPA, sumFemGPA);
     
     void OpenFiles(char ch, float gpa)
     {
          ifstream inFile;
          ofstream outFile;
    inFile.open ("Ch7_Ex4Data.txt");
    outFile.open ("Ch7_Ex4Out.txt"); …
baconswife 0 Junior Poster in Training

My program is supposed to open files, initialize variables, use the functions sumGrades, averageGrade and printResults. I am having some errors and was hoping someone could help me out. To begin with some errors I'm getting are:
line 10- two few arguments to function 'void printResult(int, int, float, float, float, float)'
line 33- at this point in file
in function 'void OpenFiles(char, float)':
line 71 'MaleGPA' undeclared (first use this function)
line 73 'avgMaleGPA' undeclared (first use this function)
line 73 'femGPA' undeclared (first use this function)
line 76 'FemGPA' undeclared (first use this function)
line 76 'GPA' undeclared (first use this function)
line 77 'countFem' undeclared (first use this function)
line 78 'avgFemGPA' undeclared (first use this function)

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
void OpenFiles(char ch, float gpa);
void initialize(int countFemale, int countMale, float sumFemGPA, float sumMaleGPA);
void sumGrades(int countFemale, int countMale, float sumMaleGPA, float sumFemGPA);
void averageGrades(float avgFemGPA, float avgMaleGPA);
void printResult(int countFemale, int countMale, float avgMaleGPA, float avgFemGPA, float sumMaleGPA, float sumFemGPA);

int main ()
{
    ifstream inFile;
    ofstream outFile;
    char ch;
    float gpa;
    float avgFemGPA, avgMaleGPA;
    int countFemale, countMale;
    float FemGPA, MaleGPA, sumFemGPA, sumMaleGPA;
    
    initialize(countFemale, countMale, sumFemGPA, sumMaleGPA);
    
    OpenFiles(ch, gpa);
    
    while(!inFile.eof())
    {
     sumGrades(countFemale, countMale, sumMaleGPA, sumFemGPA);
     inFile >> ch >> gpa;
     averageGrades(avgFemGPA, avgMaleGPA);
     }
     
     printResult(countFemale, countMale, sumMaleGPA, sumFemGPA);
     }
     
     void OpenFiles(char ch, float gpa)
     {
          ifstream inFile;
          ofstream outFile;
    inFile.open ("Ch7_Ex4Data.txt");
    outFile.open ("Ch7_Ex4Out.txt");
if(!inFile)
{
           cout << "Cannot open input file." …
baconswife 0 Junior Poster in Training

Rereading the problem changed everything, can anyone tell me why my diameter is coming out to 0?

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
const double pi = 3.1416;

float CalculateDiameter (float radius);

float CalculateCircumference (float radius);

float CalculateRadius (float x1, float x2, float y1, float y2);

float CalculateArea (float radius);

int main () 
{
    
    float x1; 
    float x2;
    float y1, y2;
    float diameter, circumference, area, radius;

    cout << fixed << showpoint;
    cout << setprecision (2);


    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
   
    diameter = CalculateDiameter (radius);
    cout << "The diameter of the circle is: " << diameter << " " << endl;


   radius = CalculateRadius (x1, x2, y1, y2);
   
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    
    circumference = CalculateCircumference (radius);
    
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    
    area = CalculateArea (radius);
    
    cout << "The area of the circle is: " << area << " " << endl;
    
    cout << ' ' << endl;
    
   
    system ("pause");

    return 0;
    
} 

float CalculateRadius (float x1, float x2, float y1, float y2)
{
      return sqrt (pow (x2 - x1, 2) + pow(y2 - y1, 2));
}

float CalculateDiameter (float radius)
{
      return radius * 2;
} …
baconswife 0 Junior Poster in Training

I am getting the error x undeclared on line 26. What I currently have is

#include <iostream>

using namespace std;
int secret (int x)
	{
		int i, j;
		i = 2 * x;
		if (i > 10)
			j = x / 2;
		else
			j = x / 3;
		return j - 1;
	}

	int another(int a, int b)
	{
		int i, j;
		j = 0;
		for ( i = a; i <= b; i++)
		      j = j + i;

		return j;
	}
int main ()
{
    cout << secret (x) << endl;
    system ("pause");
	return 0;
       }
baconswife 0 Junior Poster in Training

My next question is on "assuming x, y and k are int variables what is the output of x=10; cout << secret (x) << endl;

int secret (int x)
	{
		int i, j;
		i = 2 * x;
		if (i > 10)
			j = x / 2;
		else
			j = x / 3;
		return j – 1;
	}

	int another(int a, int b)
	{
		int i, j;
		j = 0;
		for ( i = a; i <= b; i++)
		      j = j + i;

		return j;
	}
baconswife 0 Junior Poster in Training

I have typed this many ways into dev-c++ trying to figure out how to figure out the output but it always comes back with errors no matter what headers I have used and other things. Can anyone give me some ideas? I don't want the answer, just ideas on how to find it. Being given the answer won't help me learn how to solve future problems. The problem is:
Consider the following function:

int mystery (int x, double y, char ch)
{
    int u;
    if ('A' <= ch && ch <= 'R')
       return (2 * x + static_cast<int> (y));
    else
       return (static_cast<int> (2 * y) - x);
}

what is the output of the following C++ statement?
cout << mystery (5, 4.3, 'B') << endl;

baconswife 0 Junior Poster in Training

Okay, I think I have fixed everything now. Will someone please look at this and tell me what they think? Will you also please look over my notes on the program as well as this algorithm: A. Declare the headers
B. Declare functions
C. Declare the variables
D. Set format of output to two decimal places
E. Request input from user
F. Calculate the distance between the points, radius, circumference and area using the function statements
G. Output the calculations

//Header Declaration
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
//Declare pi as a constant
const double pi = 3.1416;

//Declare Functions
float CalculateDistance (float x1, float x2, float y1, float y2);

float CalculateCircumference (float radius);

float CalculateRadius (float distance);

float CalculateArea (float radius);

int main () 
{
    // Variable Declaration
    float x1; 
    float x2;
    float y1, y2;
    float distance, circumference, area, radius;

//Set format of output to two decimal places
    cout << fixed << showpoint;
    cout << setprecision (2);

// Prompt the user to input the center point and one other point on the circle
    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    //Calculate the distance of the circle based on the formula provided
    distance = CalculateDistance (x1, x2, y1, y2);
    //output what the distance is …
baconswife 0 Junior Poster in Training

I have gotten it down to one error. On line 73 it is saying invalid function declaration

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;

float CalculateDistance;

float CalculateCircumference (float radius);

float CalculateRadius (float distance);

float CalculateArea (float radius);

int main () 
{
    
    float x1; 
    float x2;
    float y1, y2;
    float distance, circumference, area, radius;


    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    
    distance = CalculateDistance;
    
    cout << "The distance of the circle is: " << distance << " " << endl;


   radius = CalculateRadius (distance);
   
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    
    circumference = CalculateCircumference (radius);
    
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    
    CalculateArea (radius);
    
    cout << "The area of the circle is: " << area << " " << endl;
    
    cout << ' ' << endl;
    
   
    system ("pause");

    return 0;
} 

float CalculateDistance
{
      return sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
}

float CalculateRadius (float distance)
{
      return distance;
}

float CalculateCircumference (float radius)
{
    return 2 * pi * radius;
}

float CalculateArea (float radius)
{
      return (radius * radius) * pi;
}
baconswife 0 Junior Poster in Training

The problem verbatim when describing radius states "radius: This function takes as its parameters four numbers that represent the center and a point on the circle, cals the function distance to find the radius of a circle and returns the circle's radius" So if anything it is radius I need to get rid of but I'm not sure if I need to get rid of it. Distance is the distance between any 2 points on the circle but in this case the user can only input the center and a point which will then output the same number for radius

baconswife 0 Junior Poster in Training

I changed a bit but am slightly overwhelmed by how much I need to change.
here are some of the errors I have, I figure once I can solve those problems I can solve the rest, I have a ton more errors though:
25 too few arguments to function `float CalculateRadius(float, float, float, float)'
50 at this point in file
50 At global scope:
72 redefinition of `float CalculateDistance'
21 `float CalculateDistance' previously declared here
72 `x1' was not declared in this scope
72 `x2' was not declared in this scope
72 `y2' was not declared in this scope
73 expected `,' or `;' before '{' token
77 `float CalculateRadius' redeclared as different kind of symbol
25 previous declaration of `float CalculateRadius(float, float, float, float)'
77 declaration of `float CalculateRadius'
25 conflicts with previous declaration `float CalculateRadius(float, float, float, float)'
78 cannot resolve overloaded function `distance' based on conversion to type `float'

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;

float CalculateDistance;

float CalculateCircumference (float radius);

float CalculateRadius (float x1, float x2, float y1, float y2);

float CalculateArea (float radius);

int main () 
{
    float x1; 
    float x2;
    float y1, y2;
    float distance, circumference, area, radius;

    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on …
baconswife 0 Junior Poster in Training

I'm still having some issues but have corrected some more issues

//***************************************************************
// Author: Nancy Gutierrez
// Program number 6: Page 341
// CSC 160-C11
// Professor Terri Henderson
// October 24, 2010
// **************************************************************

// This program outputs the distance, radius, circumference and area of a circle
// based on the center point and point on the circle the user inputs.

//Header Declaration
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;

float CalculateDistance;

float CalculateCircumference (float radius);

float CalculateRadius (float distance);

float CalculateArea (float radius);

int main () 
{
    // Variable Declaration
    float x1; 
    float x2;
    float y1, y2;
    float distance, circumference, area, radius;
    circumference = pi * radius * 2;

// Prompt the user to input the center point and one other point on the circle
    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    //Calculate the distance of the circle based on the formula provided
    float CalculateDistance;
    //output what the distance is
    cout << "The diameter of the circle is: " << distance << " " << endl;

// Radius and distance are going to be the same so set radius equal to distance
   float CalculateRadius (float distance);
   //output what the radius is
    cout << "The radius of the circle is: " << radius << " …
baconswife 0 Junior Poster in Training

well to begin with line 73 x2 hasn't been declared, y1 is not a type, y2 has not been declared, ISO c ++ forbids declaration of 'parameter' with no type

baconswife 0 Junior Poster in Training

I've modified further to get

//***************************************************************
// Author: Nancy Gutierrez
// Program number 6: Page 341
// CSC 160-C11
// Professor Terri Henderson
// October 24, 2010
// **************************************************************

// This program outputs the distance, radius, circumference and area of a circle
// based on the center point and point on the circle the user inputs.

//Header Declaration
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;

float CalculateDistance;

float CalculateCircumference (float radius);

float CalculateRadius (float distance);

float CalculateArea (float radius);

int main () 
{
    // Variable Declaration
    float x1; 
    float x2;
    float y1, y2;
    float distance, circumference, area, radius;
    circumference = pi * radius * 2;

// Prompt the user to input the center point and one other point on the circle
    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    //Calculate the distance of the circle based on the formula provided
    float CalculateDistance;
    //output what the distance is
    cout << "The diameter of the circle is: " << distance << " " << endl;

// Radius and distance are going to be the same so set radius equal to distance
   float CalculateRadius (float distance);
   //output what the radius is
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    //Calculate circumference using …
baconswife 0 Junior Poster in Training

How do I fix what I did? I don't even really know what I did wrong.

//***************************************************************
// Author: Nancy Gutierrez
// Program number 6: Page 341
// CSC 160-C11
// Professor Terri Henderson
// October 24, 2010
// **************************************************************

// This program outputs the distance, radius, circumference and area of a circle
// based on the center point and point on the circle the user inputs.

//Header Declaration
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;

float CalculateDistance (float x1, x2, y1, y2);

float CalculateCircumference (float radius);

float CalculateRadius (float distance);

float CalculateArea (float radius);

int main () 
{
    // Variable Declaration
    float x1, x2, y1, y2;
    float distance, circumference, area, radius;
    circumference = pi * radius * 2;

// Prompt the user to input the center point and one other point on the circle
    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    //Calculate the distance of the circle based on the formula provided
    CalculateDistance(float x1, x2, y1, y2);
    //output what the distance is
    cout << "The diameter of the circle is: " << distance << " " << endl;

// Radius and distance are going to be the same so set radius equal to distance
   CalculateRadius (float distance);
   //output what the radius is
    cout << "The …
baconswife 0 Junior Poster in Training

Another thing that I was wondering is how would i put what I have in functions and not have it in main?

baconswife 0 Junior Poster in Training

Here is how I have it written now, and someone also stated "For more elegance, I would set up radius, circumference, and area as functions to call in the main section" I have read on this but am still slightly confused on how to do it. Is there anyway someone can give me an example or guide me a bit on how to do that? Thank you everyone for your time!

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double pi = 3.1416;
int main () 
{

    float x1, x2, y1, y2;
    float distance, circumference, area, radius;

    cout << "Enter the x and y coordinates of the center of the circle: ";
    cin >> x1 >> y1;
    cout << "Enter the x and y coordinates of a point on the circle: ";
    cin >> x2 >> y2;
    cout << endl;
    
    distance = sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));

    cout << "The diameter of the circle is: " << distance << " " << endl;

   radius = distance;
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    circumference = 2 * pi * radius;
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    area = (radius * radius) * pi;
    cout << "The area of the circle is: " << area << " " << endl;
    cout << ' ' << endl;
    
    system ("pause"); …
baconswife 0 Junior Poster in Training

I changed how I am writing it entirely. Please take a look at this one instead

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
int main () 
{
    float x1, x2, y1, y2;
    float dx, dy;
    float distance, circumference, area, radius;
    float dresult, dsquared;
    

    
    cout << "Enter the center point of the circle: ";
    cin >> (x1, y1);
    cout << "Enter a point on the circle: ";
    cin >> (x2, y2);
    cout << endl;
    
    distance = sqrt ((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1));
    cout << "The distance between the two points on the circle is: " << distance << " " << endl;

   radius = distance;
    cout << "The radius of the circle is: " << radius << " " << endl;
    
    circumference = 3.1416 * (radius * 2);
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
    area = (radius * radius) * 3.1416;
    cout << "The area of a circle is: " << area << " " << endl;
    cout << ' ' << endl;

    system ("pause");

    return 0;
}
baconswife 0 Junior Poster in Training

With this program I need to be able to find the circumference, area, diameter and radius of a circle. Here is what I have, please let me know of any advice you have:

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
int main () 
{
    int x1;
    int x2;
    int y1;
    int y2;
    int dx;
    int dy;
    
    cout << "Enter the center point of the circle: " << endl;
    cin >> (x1, y1) >> (x2, y2);
    cout << "Enter a point on the circle" << endl;
    cin >> (x1, y1) >> (x2, y2);
    cout << endl;
    
int distance (x1, y1, x2, y2)
{
    dx = x2 - x1;
    dy = y2 - y1;
    float dsquared = dx * dx + dy * dy;
    float dresult = sqrt (dsquared);
    cout << "The distance of the circle is: " << dresult << " " << endl;
}

int radius (x1, y1, x2, y2)
{
    float radius = distance
    float dresult = area (radius);
    cout << "The radius of the circle is: " << dresult << " " << endl;
}

int circumference (float radius)
{
    float circumference = 3.1416 * (radius * 2);
    cout << "The circumference of the circle is: " << circumference << " " << endl;
    
int area (float radius)
{
    float area = (radius * radius) * 3.1416;
    cout << "The area of a circle is: " << area << " " << endl;
    cout << ' ' << endl;

    system ("pause");

    return 0;
}
baconswife 0 Junior Poster in Training

I have everything fixed but now can anyone give me guidance on how set it up to find whether it is prime or not by using the fact that the input number is not divisible by any odd integer less than or equal to the square root of the number if it is a prime number?

// This program tests to see whether an input number is a prime number or not
// it then outputs the number the user entered and states if it is or is not
// a prime number.

//Header Declaration
#include <iostream>
#include <iomanip>

using namespace std;
int main () 
{
    //Variable Declaration
int num;
int i;
//Request user input
cout << "Please enter a positive integer other than 1:" << endl;
cin >> num;
cout << "The number you entered is: " << num << endl;
cout << "  " << endl;
//Input the information needed to calculate whether the number is prime or not
if (num <=1)
//Set the output to state that 1 or a negative integer is a non-prime number
cout << num << " is not a prime number." << endl;

else
{ 
    for (i = 2; i < num; i++)
{
    if (num % i == 0)
{
    //Set the output to state that anything meeting the above conditions is a
    //non-prime number.
cout << num << " is not a prime number." << endl;
cout << "  " << endl;
system ("pause");
return 0;
}
}
//Set …
baconswife 0 Junior Poster in Training

I think have everything fixed except the fact it is outputting 1 as a prime number. if anyone can help with this that would be great.

#include <iostream>
#include <iomanip>

using namespace std;
int main () 
{
int num;
int i;
cout << "Please enter a positive integer other than 1" << endl;
cin >> num;
cout << "The number you entered is: " << num << endl;
cout << "  " << endl;
bool isPrime = true;
for (i = 2; i < num; i++)
{
    if (num % i == 0)
    {
isPrime = false;
break;
}
}
if (isPrime == true)
{
cout << num << " is a prime number." << endl;
cout << "  " << endl;
}

else if (isPrime == false)
{
cout << num <<  " is not a prime number." << endl;
cout << "  " << endl;
}
system ("pause");
return 0;
}
baconswife 0 Junior Poster in Training

I have updated this a lot more and thought I would see if anyone had any advice.

#include <iostream>
#include <iomanip>

using namespace std;
int main () 
{
int num;
bool isPrime = true;
int i;
cout << "Please enter a positive integer other than 1" << endl;
cin >> num;
cout << "The number you entered is: " << num << endl;
cout << "  " << endl;
for (i = 2; i <=num; i++)
{
    if (num % i == 0);
    {
isPrime = false;
break;
}
}
if (isPrime == true)
{
cout << num << " is a prime number." << endl;
cout << "  " << endl;
}

else if (isPrime == false)
{
cout << num <<  " is not a prime number." << endl;
cout << "  " << endl;
}
system ("pause");
return 0;
}
baconswife 0 Junior Poster in Training

It outputs both answers for all of my input, any help?

#include <iostream>
#include <iomanip>

using namespace std;
int main () 
{
int num;
int i;
int j;
cout << "Please enter a positive integer other than 1" << endl;
cin >> num;
for (i = 3; i <=num; i++);
    if (num % 2 != 0);
cout << "Is a prime number." << endl;

if(num%2 == 0);
    cout << "Not a prime number." << endl;
system ("pause");
return 0;
}
baconswife 0 Junior Poster in Training

So I almost had it but was interrupted. This is now what I have

#include <iostream>
#include <iomanip>

using namespace std;
int main () 
{
int num;
int i;
cout << "Please enter a positive integer other than 1" << endl;
cin >> num;
if (i = 3; i <=num; i++)
cout << "Is a prime number" << endl;
else
{
 if (num % i == 0)
{
    cout << "Not a prime number." << endl;
    system ("pause");
return 0;
    }
}
system ("pause");
return 0;
}
baconswife 0 Junior Poster in Training

I modified it but still feel I have a major error somewhere. Any ideas?

#include <iostream>
#include <iomanip>

using namespace std;
int main () 
{
int num;
int i;
cout << "Please enter a positive integer. Enter # to quit." << endl;
cin >> num;
if (num <=1)
cout << "Not a prime number" << endl;
else
{
for (i = 3; i <=num; i++)
cout << "Is a prime number." << endl;
{
 if (num % i == 0)
{
    cout << "Not a prime number." << endl;
    system ("pause");
return 0;
    }
}
}
system ("pause");
return 0;
}
baconswife 0 Junior Poster in Training

I guess I don't get exactly how the whole thing doesn't make sense, I wrote it up and then compared it to what others had and have something very similar.

baconswife 0 Junior Poster in Training

I am writing a program that outputs whether or not a number is prime. Can anyone help me find where my syntax error is? Also, i get that i = 3; i <= num; i++ would be true for it being a prime number from the other forums I have read but I honestly don't get why, can someone explain? I get everything else I have done thus far.

#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
    int num;
    int i;
    
    cout << "Please enter a positive integer: " << endl;
    
    if (num <=1)
    return false;
else if (num == 2)
    return true;
else if (num % 2 == 0)
    return false;
else (i = 3; i <= num; i++);
    return true;
    
    system ("pause");

    return 0;
}
baconswife 0 Junior Poster in Training

Not sure, it's what it started out as. I'm switching it I just hadn't yet