jmcorpse 0 Light Poster

Thanks for your help. But I figured it out right after you posted Ezzaral. Thanks for the help.

jmcorpse 0 Light Poster

Can someone help me figure out what I am doing wrong here. I think I may be running my head into this way to many times to see what is wrong with it. The error code is posted below.

import java.util.Scanner;
public class userName {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
        getNames(firstName, lastName);
		userPassword(firstName, lastName);//function call
	
	}
    public static void getNames(String firstName, String lastName){
		Scanner kbd = new Scanner(System.in);//Creates new scanner
        System.out.println("Please enter your first and middle names.");//prompts user for input
		firstName = kbd.nextLine();//first and middle names are entered here
		System.out.println("Please enter your last name.");//prompts user for input
		lastName = kbd.nextLine();//last name is entered here
    }
	
    public static void userPassword(String firstName, String lastName){
    	int x = 1;//used to print out the first letter of the first name
    	int y = 4;//used to print out the first four letters of the last name 
    	//System.out.println("Your first and middle names are " + firstName);//test to see if firstName was passed correctly
    	//System.out.println(firstName.substring(0,x));//test to see if the print out is abbreviated
    	//System.out.println("Your last name is " + lastName);//test to see if lastName was passed correctly
    	//System.out.println(lastName.substring(0,y));//test to see if the print out is abbreviated
    	System.out.println("Your user password is " + firstName.substring(0,x) + lastName.substring(0,y));
    	
    }
}

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
firstName cannot be resolved to a variable
lastName cannot be resolved to a variable
firstName cannot be resolved to a variable
lastName cannot be resolved to …

jmcorpse 0 Light Poster

This is what I am suppose to do: Write a program that maintains a high score table of five entries, where each entry is made up of a player's name and score. The table should store the entries in order, from highest score to lowest. Your program should initialize the table using your name and 1000 for all five entries. Next, your program should display the entries and allow a player to add a new one. Your program should accept a name and a score for the potential new entry. If the score is greater than or equal to the lowest score in the table, your program should insert the new entry at the correct position, adjust the rest of the table accordingly, and display a message saying that the entry was inserted. Otherwise, your program should display a message telling the player that the score was too low for the entry to be added. Your program should continue to display the table and allow the player to add new entries as long as he or she wants. (Hint: Your program doesn't have to do a full sort of the entries when a new one is added. You can assume that the entries are already sorted; a new entry needs only to be inserted at the correct position with the rest of the table adjusted accordingly)

This is how far I have gotten and I believe that I have completely lost myself. I am getting these errors:

high_score_2.cpp: …

jmcorpse 0 Light Poster

Hello,

Can some one give me a hand on my search algorithm? I know it's not working right and am not sure how to make it work properly. It is on line #'s 69 to 73. It has to search for the name that is already stored in the array and return either cout statements provided. Any help would be appreciated.

#include<iostream>
#include<cstring>

using namespace std;
void printArray(char**,int);//Function declaration
char** showNames(char **names,char **names2,int& size, int& size2, int& size3);//Char names declaration
char** addEntry(char **names,char **names2,int& size, int& size2);//Char addEntry declaration
char** deleteEntry(char **names,char **names2,int& size, int& size2);//Char deleteEntry declaration

int main()
{

     int size = 5;//Constant size for size
     int size2 = 20;//Constant size for size2
     int size3 = 1;//Constant size for siz3
     char **names  =  new char*[size];//Creates a double pointer that points to an array of 5 strings
     char **names2 = new char*[size3];
     
     showNames(names,names2,size,size2, size3);//Function call for names  
     cout << "\nOriginal List" << endl;
     printArray(names,size);//Prints out the names to test that they are being inputed correctly
     cout << "\nOne name added to the list" << endl;
     names = addEntry(names,names2,size,size2);//newname is being set to the addentry function
     printArray(names,size);//Prints out the results
     cout << "\nOne name deleted from the list" << endl;
     names = deleteEntry(names,names2,size,size2);//newname is being set to the addentry function
     printArray(names,size);//Prints out the results

return 0;
}

char** showNames(char **names,char **names2,int& size, int& size2, int& size3)
{

     for(char i = 0; i < size; i++)//for loop to iterate across an array
     names[i] = new char[size2];//Creates a dynamic array …
jmcorpse 0 Light Poster

I have to write a program that creates a dynamic array of five strings, store them and be able to access them.

This is the code I have written so far. The console receives the information that is inputted, but I believe does not store them. Also I commented out the cout on line 33 that was suppose to test the entry. Mainly because it makes the program go into an infinite loop. I've got a big suspicion that the whole thing is wrong, but I am not a hundred percent sure. Any help you can offer would be greatly appreciated.

#include<iostream>
#include <string>


using namespace std;
typedef char* CharArray;
const int NAMES = 5;
void getNames(string Name, CharArray nameArray);//getNames function declaration

int main()
{
     CharArray nameArray;
     nameArray = new char[NAMES];
     string Name;//Variable name for this string

     getNames(Name, nameArray);//Function call for getNames

return 0;
}

void getNames(string Name, CharArray nameArray)//Function definition
{     
     for ( int i = 0; i < NAMES; i++ )//Used to iterate the strings that are being created.
     {
          cout << "\nPlease enter name " << i + 1 << ".";//Output o instrct user to enter names.
          cin  >> Name;//Recieves info from user
     }
     // cout << Name:
}
jmcorpse 0 Light Poster

Thanks, now that I have had a chance to step away from the console that makes sense

jmcorpse 0 Light Poster

They are int.

jmcorpse 0 Light Poster

You need your curly braces for example:

#include<iostream>


using namespace std;



int main()
{
    int x = 0;
    int y = 0;
    
    
    if ( x != y )
    {
         cout << "x does not equal y";
    }
    else
    {
        cout << "x does equal y";
    }
    
    

  return 0;
}

Just change the values of x and y to see the example. Without them the if and else will only work on the line immediately following these statements.

jmcorpse 0 Light Poster

How can I go about padding an array of a certain size so that it will align with another one?

For example I have an addition problem I am working out and cannot find the solution to.
When my program prints it out it will look like this:

1234567 should be ----> 1234567
1234 should be ----> 0001234
------- -------
2468342 should be ----> 1235801

The firs numbers add correctly and then afterwards they are junk numbers. How could I pad the second array which contains the 1234 to shift to the right. I believe it may have something to do with the #include<iomanip> library. Also the size of the arrays are not static they are chosen by the user at the beginning of the program, so the I think the padding will have to be dynamic.

I don't want the code but any suggestions or nudges in the right direction would be helpful.

jmcorpse 0 Light Poster

I fixed all the problems from earlier now I just have some minor issues that I can't seem to iron out. The math portion of my program works, what I am having trouble with is carrying over the number and creating the next column. For example 9 + 1 = 10 that would mean 0 in the ones column and 1 in the tens column. I can't get the program to do this when it reaches the first number in the number if it is greater than ten. And also if the first number that was entered by the user is larger than the second I think I need to pad the second number to the right so it will add properly and I do not know how to do make that happen. I could sure use some advice.

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


using namespace std;
typedef int* IntArrayPtr;
const int size3 = 20;
const int TEN = 10;//Constant for the number10
const int ASCII = 48;//Constant for the ASCII character 0
const int ASCII9 = 57;//Constant for the ASCII character 9
void getSize(int& size1, int& size2);//Function declaration for getSize
void fillZero(int total[], int sum[], int& size1, int& size2);
void createArrays(int a[], int b[], int& size1, int& size2);//Function declaration for createArrays
void fillArray1(int a[], int& size1, int conInput1[]);//Function declaration for fillArray1
void fillArray2(int b[], int& size2, int conInput2[]);//Function declaration for fillArray2
void addition(int conInput1[], int conInput2[], int total[], int sum[], int& size1);//Function declaration for addition
void carry(int total[], int …
jmcorpse 0 Light Poster

Ok, I figured out the problem with it crashing. It was coming from how I was intializing a and b to zero, so I removed it and it worked properly. Would I set them to zero like an array or how you set them to zero using the int* a = Null?

#include<iostream>
#include<cstddef>

using namespace std;
typedef int* IntArrayPtr;
void getSize(int& size1, int& size2);//Function declaration for getSize
void createArrays(int a[], int b[], int& size1, int& size2);//Function declaration for createArrays
void fillArrays(int a[], int b[], int& size1, int& size2);//Function declaration for fillArrays


int main()
{

     int size1;//Variable that will be passed from one function to another
     int size2;//Variable that will be passed from one function to another

     getSize(size1, size2);//Funcion call for getSize

     int *a = new int[size1];;//Sets pointer a equal to new int[size1] where the size is that of the number entered by the user
     int *b = new int[size2];//Sets pointer b equal to new int[size2] where the size is that of the number entered by the user

     createArrays(a, b, size1, size2);//Function call for createArrays
     fillArrays(a, b, size1, size2);//Function call for fillArrays

  return 0;
}

void getSize(int& size1, int& size2)//Function definition for getSize
{
     cout << "\nEnter the size of the first number to be added:" << endl;//Asks user to input the size of the number( number of digits) to use to create a dynamic array
     cin  >> size1;//Input from user
     //cout << size1 << endl;//Test to show input is correct
     
     cout << "\nEnter the size of the second …
jmcorpse 0 Light Poster

Like this?

int *a = new int[size2];;//Sets pointer a equal to new int[size1] where the size is that of the number entered by the user
     int *b = new int[size2];//Sets pointer b equal to new int[size2] where the size is that of the number entered by the user

It compiles and then when I run in it. The console freezes and shuts down.

jmcorpse 0 Light Poster

Ok, I moved the code to establish the dynamic arrays after getSize(). For some reason my brain is becoming stuck in slow motion I can't figure out the warning that the compiler is giving me. I'm pretty sure it is something simple and easy to fix but is not clear to me at the moment.

Here are the errors:

In function `int main()':
cannot convert `int**' to `int*' for argument `1' to `void createArrays(int*, int&, int*, int&)'
cannot convert `int**' to `int*' for argument `1' to `void fillArrays(int*, int&, int*, int&)'

int size1;//Variable that will be passed from one function to another
     int size2;//Variable that will be passed from one function to another
     getSize(size1, size2);//Funcion call for getSize
     IntArrayPtr a[size1];
     for ( int i = 0; i < size1; i++ )
     {
          a[i] = new int[size1];//Sets pointer a equal to new int[size1] where the size is that of the number entered by the user
     }
     IntArrayPtr b[size2];
     for ( int j = 0; j < size2; j++ )
     {
          b[j] = new int[size2];//Sets pointer b equal to new int[size2] where the size is that of the number entered by the user
     }
     createArrays(a, b, size1, size2);//Function call for createArrays
     fillArrays(a, b, size1, size2);//Function call for fillArrays
jmcorpse 0 Light Poster
#include<iostream>
#include<cstddef>

using namespace std;
typedef int* IntArrayPtr;
void getSize(int& size1, int& size2);//Function declaration for getSize
void createArrays(int& size1, int& size2);//Function declaration for createArrays
void fillArrays(int& size1, int& size2);//Function declaration for fillArrays


int main()
{

     int size1;//Variable that will be passed from one function to another
     int size2;//Variable that will be passed from one function to another
     getSize(size1, size2);//Funcion call for getSize
     createArrays(size1, size2);//Function call for createArrays
     fillArrays(size1, size2);//Function call for fillArrays

  return 0;
}

void getSize(int& size1, int& size2)//Function definition for getSize
{
     cout << "\nEnter the size of the first number to be added:" << endl;//Asks user to input the size of the number( number of digits) to use to create a dynamic array
     cin  >> size1;//Input from user
     //cout << size1 << endl;//Test to show input is correct
     
     cout << "\nEnter the size of the second number to be added:" << endl;//Asks user to input the size of the number( number of digits) to use to create a dynamic array
     cin  >> size2;//Input from user
     //cout << size2 << endl;//Test to show input is correct
}

void createArrays(int& size1, int& size2)//Function definition for createArray
{
     int* a = NULL;//Sets pointer a to NULL 

     a = new int[size1];//Sets pointer a equal to new int[size1] where the size is that of the number entered by the user
     for ( int i = 0; i < size1; i++ )
     {
          a[i] = 0;//Fills all elements to zero.
          cout << a[i];//Test to outpt a[i] to make sure array is filled …
jmcorpse 0 Light Poster

I need some assistance with my code. I figured it out and have it working for the most part. I just need some help in the carrying function where all the numbers that where added we carried over with paper and pencil type arithmetic. My biggest problem now is trying to get the function to open up and print out the preceding 1 that is required. Any assistance would be appreciated.

int main()
{
     int conInput1[ARRAY_SIZE] = {7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
     int conInput2[ARRAY_SIZE] = {7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
     int newOutput[ARRAY_SIZE_2] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
     double val2;
    
     fillZero(conInput1, conInput2, newOutput);
     addition(conInput1, conInput2, newOutput);
     printResults(conInput1, conInput2, newOutput);
return 0;
}

void fillZero(int conInput1[], int conInput2[], int newOutput[])
{

     //cout << conInput1[ARRAY_SIZE];
     //cout << conInput2[ARRAY_SIZE];
     for ( int i = 0; i < ARRAY_SIZE; i++ )
     {
          newOutput[i] = 0;
          //cout << newOutput[i];
     }
}

void addition(int conInput1[], int conInput2[], int newOutput[])
{    
     for ( int i = 0; i < ARRAY_SIZE; i++ )
     {
          newOutput[i] = conInput1[i] + conInput2[i];
          //cout << conInput1[i] << "input";
          //cout << conInput2[i] << "input";
          //cout < output1[i] << "test";
     
          if (  newOutput[i] >= 10 )
          {
               carry(conInput1, conInput2, newOutput);
          }

     }
}


void carry(int conInput1[], int conInput2[], int newOutput[])
{
     int i;
     int x = 0;

     for ( i = 0; i < ARRAY_SIZE_2 + 1; i++ )
     {
          if ( newOutput[i] >= 10)
          {
               x = newOutput[i] / 10;
               //cout << x << endl;
               newOutput[i] = newOutput[i] % 10;
               //cout << " \n"<< newOutput[i] << newOutput[i];
               newOutput[i-1] = newOutput[i-1] + x;
          }
     } …
jmcorpse 0 Light Poster

My main problem right now with this code is trying to get the carry function to work. Also, I know it isn't pretty code. Could someone help me in figuring out why this isn't working the way it is suppose to. The carry function is suppose to add the carry over digit but I can't seem to pass a variable correctly. I've tried everything I could think of but can' seem to do it.

#include<iostream>
#include<cmath>

using namespace std;
const int ARRAY_SIZE = 20;
void fillZero(int conInput1[], int conInput2[], int output[]);
void mod1(int conInput1[], int conInput2[], int output[], int& trans);
void remainder(int conInput1[], int conInput2[], int output[]);
void carry(int conInput1[], int conInput2[], int output[], int& trans);
void addition(int conInput1[], int conInput2[], int output[], int& trans);
void printResults(int conInput1[], int conInput2[], int output[]);


int main()
{
     int conInput1[ARRAY_SIZE];
     int conInput2[ARRAY_SIZE];
     int output[ARRAY_SIZE];
     int trans;
    
     fillZero(conInput1, conInput2, output);
     addition(conInput1, conInput2, output, trans);
     printResults(conInput1, conInput2, output);
return 0;
}
void fillZero(int conInput1[], int conInput2[], int output[])
{
     for ( int i = 0; i < ARRAY_SIZE; i++ )
     {
          conInput1[i] = 9;
          conInput2[i] = 9;
          output[i] = 0;
          /*cout << conInput1[i];
          cout << conInput2[i];
          cout << output[i];*/
     }
}
void mod1(int conInput1[], int conInput2[], int output[], int& trans)
{
     for ( int i = 0; i < ARRAY_SIZE; i++ )
     {
          double val2;
          double val1; 
          double sum = output[i];
          val1 = sum / 10;
          modf(val1, &val2);
          //cout << endl << sum;
          //cout << endl << val1; 
          //cout << endl << &val2 << …
jmcorpse 0 Light Poster

Thanks for your help. It worked great.

jmcorpse 0 Light Poster

Can someone help me figure out how to either round up or down down the numbers? The numbers are used with the asterisks in the bar graph. I'm not sure if I should be using fmod or the round function. Any help would be appreciated.

#include<iostream>

#include<iomanip>

#include<cmath>

 

using namespace std;

string printAsterisks(double);//String function declaration

const int MONTHS = 12;



int main()

{



     double avgRain[] = {1.81, 1.04, 0.27, 7.25, 7.79, 2.88, 9.71, 5.04, 3.59, 8.80, 3.67, 2.07};

     double actRain[] = {9.57, 4.42, 4.78, 3.14, 8.72, 3.24, 6.01, 6.31, 9.76, 6.10, 8.37, 6.29};

     string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

     int month;

     int asterisk_count[MONTHS];//Variable for asterisk count





     

     

     for ( int i = 0; i < 12; i++)

     {    

          double j = avgRain[i]/1.0;

          cout.setf(ios::showpoint);

          cout.setf(ios::fixed);

          cout.precision(1);

          cout << setw(15) << left << months[i] << j << " " << endl;

     }

     







     cout << endl;
     cout << "\n *** RainFall Bargraph *** " << endl << endl;// Bar graph title bar.
     
     for (int i=0;i< MONTHS;i++)//For loop count down for months, average, actual 
     {   

          cout << endl;   
          cout << months[i]<<" " <<"Average: ";//Months output for average  
          cout << printAsterisks(avgRain[i]);//Prints out the asterisks for the totals.
          cout << endl;
          cout << months[i]<<" " <<"Actual:  ";//Months output for average 
          cout << printAsterisks(actRain[i]);//Prints out the asterisks for the totals.
          cout << endl;
       
     }
    

     

     return 0;

}

string printAsterisks(double n)//Asterisk printing function
{
     string s1 (n, 42);//Variable for the string function.
     for(int count=1; count<=n; count++)//For loop that counts …
jmcorpse 0 Light Poster

I want to say thank you to everyone in advanced for all the help that has been provided. I am currently stuck on two more items on this program. Currently I am completely stumped on how to create a bar graph using the information gathered by the program. Some reason I can't decipher how the book does it. The second part is how do I get the table and bar graph to print out to a file. Hopefully this isn't a lot that I am asking. Also thanks to Ancient Dragon for help earlier.

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<fstream>

using namespace std;

const int MONTHS = 12;//Constant for number of months.
void getAvg(double avgRain[], string months[]);//Function declaration for getAvg.
void getCurrent(int& month, string months[]);//Function declaration for getCurrent month.
void getAct(double actRain[], double avgRain[], string months[], int& month);//Function declaration for getAct.
void printTable(double avgRain[], double actRain[], string months[]);//Function declaration for printTable.
void printBaravg(double avgRain[], string months[]);//Function declaration for printBaravg.

int main()
{

     double avgRain[MONTHS];//avgRain[] variable
     double actRain[MONTHS];//actRain[] variable
     int month;//month variable
     string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};//String for the month names used in the program.

     getAvg(avgRain, months);//getAvg function call.
     //getCurrent(month, months);//getCurrent function call.
     getAct(actRain, avgRain, months, month);//getAct function call.
     printTable(avgRain, actRain, months);//printTable function call.
     //printBaravg(avgRain, months);//printBaravg function call.

     return 0;
}


void getAvg(double avgRain[], string months[])//getAvg function definition.
{
     ifstream inputFile;//Tells the program where to look for input data file.

     inputFile.open("rainfall_current.dat");//Opens the file rainfall_current file.

     for ( int i = 0; …
jmcorpse 0 Light Poster

Thanks for the help. I don't know why I couldn't think of that.

jmcorpse 0 Light Poster

I just need a little advice. This code I have written works well. The only problem I am having is that the output is not lining up and I don't know what to do. If everything was entered line by line I could get it to line up. Since it is done through a for loop I don't know what to do to get them to line up in the output. Any help would be appreciated.

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

using namespace std;

int main()
{
    int avgRain[] = {1,2,3,4,5,6,7,8,9,10,11,12};
    int actRain[] = {12,11,10,9,8,7,6,5,4,3,2,1};
    string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
    
    int x;
    int total, total2;
    
    cout << "Month" << setw(22) << " Average Rainfall" << setw(22) << " Actual Rainfall" << setw(22) << " Total Below Average" << setw(22) << " Total Above Average" << endl << endl;
    
     for (int i = 0; i < 12; i++)
     {    
          total = avgRain[i] - actRain[i];
          total2 = actRain[i] - avgRain[i];
          //cout << total;
          if( total < 0 )
          {
              total = 0;
              //cout << total;
          }
          if ( total2 < 0)
          {
               total2 = 0;
               //cout << total2;
          }
                   
          cout << months[i] << setw(13) << avgRain[i] << setw(22) << actRain[i] << setw(18) << total << setw(18) << total2 << endl;
    
    
     }
     return 0;
}
jmcorpse 0 Light Poster

Hello,

I have this probelm posted below. I pretty much have it figured out and it is still in rough draft form. I know it could be optimized better but, I'm not quite sure how to get it to look better. Although, the main reason I am looking for help is for the input of the current month and the previous rainfall data. I have to have the months go backwards while the program receives the data. I tried changing the for loop and all I got was a screen filled with programing characters. I'm not sure what I have to do to get it operational. The getMonth function starts on line 36 and ends on 55. The Actual Rainfall function starts on line 69 and ends on 80. These two functions are where I need the help on.

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

using namespace std;

const int MONTHS = 12;//Constant for number of months.
void getMonth(string months[]);// Asks user for current month.
void getAvg(double avgRain[],string months[], int& i);
void getAct(double actRain[],string months[], int& j);
void printTable(double avgRain[], double actRain[],string months[], double& totalAvg, double& totalAct, double& sum3, double& sum4, double& sum5, double& sum6, double& sum7, double& sum8, double& sum9, double& sum10, double& sum11, double& sum12, double& sum13, double& sum14, double& sum15, double& sum16, double& sum17, double& sum18, double& sum19, double& sum20, double& sum21, double& sum22, double& sum23, double& sum24, double& sum25, double& sum26);
void totals(double avgRain[], double actRain[],string months[], int& i, int& j, double& totalAvg, double& totalAct, double& sum3, …
jmcorpse 0 Light Poster

Thanks for your help. I think I was starring at the problem to long for a result to come to me.

jmcorpse 0 Light Poster

This is what I have to do.

Write a program that has a Fibonacci number calculating function. The function will take an integer as a parameter which is the Fibonacci number to calculate, and return the Fibonacci number. Then use this function to calculate the sum of every Fibonacci number that is divisible by 3 or 5, (hint - use modulus division). Do this for all Fibonacci numbers less than 4,000,000. Make sure that you document your program.

I have most of the code done and the only part I can't figure out is how to get the function that gets the sun of every Fibonacci number that is divisible by 3 or 5. I've tried a for loop but the numbers just kept scrolling on the output. This thing has been plaguing me for the past day and a half. Any help would be greatly appreciated.

using namespace std;
void getInput(int& numbers);//Function declaration to get information
void calculations(int& numbers, int& fib3);//Function declaration to perform calculations
void getNumbersthree(int& fib3);
void printOutput(int& numbers, int& fib3);//Function declaration to print out the requested information.
char getResponse();//Function declaration to repeat program.
const int MILLIONS = 4000000;
const int MAXFIBNUM = 33;
const int ZERO = 0;

int main()
{
    int numbers = 2, fib3;//Variables that are used in main.
    char response;//Variables that are used in main.
    do
    {         
         getInput(numbers);//Used to call the getInput function.
         calculations(numbers, fib3);//Used to call the calculations function.
         getNumbersthree(fib3);//Used to call the getNumbersthree function.
         printOutput(numbers, fib3);//Used to call …
jmcorpse 0 Light Poster

Hello,

I had quite a few bugs with this program and it's fore-bearer. I got all but one of them fixed and it's in one of my if-else loops. When the program runs it runs good and then when it gets to the loop it only pulls out the first part of the if-else and only shows it in the AM mode. The PM mode should be the one that is used. The if loop that is called when the time is greater than a certain time works fine. I am probably sure it's going to be a simple problem, but I can't seem to grasp it. The if-else loop that is not working is on lines 88 - 92.

#include<iostream>
#include<cmath>

void getTime(int&hour, int& minute, int& waitH, int& waitM, char& let1, char& let2, char& colon);//Declaration for the function that receives input from the user.
void conversion(int& hour, int& minute, int& waitH, int& waitM, int& days, int& nHours, int& min1, char& colon);//Declaration for the function that does the calculation converting seconds into minutes, hours and days.
void printTime(int& days, int& nHours, int& min1, char& let1, char& colon);//Declaration for the function that prints out the results onto the screen.
char getResponse(int& hour, int& minute, int& waitH, int& waitM, int& days, int& nHours, int& min1, char& let1, char& let2, char& colon);//Declaration for the funtion that asks the user if he/she would like to repeat the program.
const int SECONDS_IN_DAY = 86400;//Constant for the number of seconds in a day.
const …
jmcorpse 0 Light Poster

Thanks,
I don't know why i didn't see it earlier. I added the variable nDays to the function calls of timeCalc and printTime and its producing the correct values.

jmcorpse 0 Light Poster

On lines 60, 66 and 84.

jmcorpse 0 Light Poster

Hello,

I'm a little lost as to how to get the day part of my function to come up properly without a garbage number as it wants to do at the moment. I have everything else working well until it doesn't return the day on line .

#include<iostream>
#include<cmath>

void getTime(int& cHours,int& cMinutes,int& hWait, int& mWait, char colon);
void timeCalc(int& cHours,int& cMinutes,int& hWait, int& mWait, int& waitH,int& waitM);
void printTime(int& cHours,int& cMinutes,int& hWait, int& mWait, int& waitH,int& waitM, int& nDays);
char getResponse();


int main()
{
    int cHours,cMinutes,hWait,mWait,waitH,waitM,nMin,nDays;
    char rerun,colon;

    do
    {
         getTime(cHours,cMinutes,hWait,mWait,colon);
	     timeCalc(cHours,cMinutes,hWait,mWait,waitH,waitM);
	     printTime(cHours,cMinutes,hWait,mWait,waitH,waitM,nDays);
	     rerun = getResponse();

    }while(rerun == 'y');
    return 0;
}

void getTime(int&  cHours,int& cMinutes,int& hWait, int& mWait, char colon)
{
     using namespace std;
    
     cout << "\nPlease enter the current time in 24 hour notation HH:MM." << endl;
     cin  >> cHours >> colon >> cMinutes;
     cout << "\nPlease enter the amount of time to wait. Example HH:MM." << endl;
     cin  >> hWait >> colon >> mWait;

    //cout << "\nThe time is: " << cHours << colon << cMinutes << endl;
    //cout << "\nThe wait is: " << hWait << colon << mWait <<endl;
    
}

void timeCalc(int& cHours,int& cMinutes,int& hWait, int& mWait, int& waitH,int& waitM)
{
     using namespace std;
     int nHours,nDays;

     waitH = cHours + hWait;
     waitM = cMinutes + mWait;
        
     if ( waitM > 59 )
	 {
      nHours = waitM /60;
      waitM = waitM % 60;
      waitH = waitH + nHours;
      
      cout << waitH << " hours" <<endl;
      //cout << nHours << "hours2";
      //cout << waitM …
jmcorpse 0 Light Poster

I think there may be a math error in my program and I may not be seeing it. Is it possible for someone to go over it just to make sure it is ok. I have done everything I could think of to try to fix it, but it is eluding me. Thanks. I think the problem is near line 121.

#include<iostream>
#include<cmath>

void printMenu();//Function to get information from user
void getInputS(double& feet,double& inches);//Gathers the feet and inches from the user.
void getInputM(double& meters,double& cm);//Gathers the meters and centimeters from the user.
void standtometcon(double& feet,double& inches,double& meters,double& cm);//Declaration for standard conversion.
void mettostandcon(double& feet,double& inches,double& meters,double& cm);//Declaration for Metric conversion.
void printOutput(double& feet,double& inches);//Prints out the data after the calculations have been made.
void printOutput1(double& meters,double& cm);//Prints out the data after the calculations have been made.
const double meters_per_feet = 0.3048;//Constant for meters per foot.
const double feet_per_meter = 3.2808398950131235;//Constant for feet in a meter.
char getResponse();//Function that will ask the user to decide about repeating the program.


    int main()
    {
        //Variables for the program.
        double feet,inches,meters,cm;//Variables for the program.
        char rerun;
    do//Beginning of the do-while loop.
    {
         
         printMenu();//The only function call in the entire program that exists in the main body.
                     
    }while (rerun == 'y'); //End of do-while loop.     
    return 0;    
    }
    
    void printMenu()//This function gathers the needed requirments of feet and inches. It also calls all other functions that are used in this function other than itself.
    {   
        using namespace std;//Used per function no longer used globally. …
jmcorpse 0 Light Poster

I closed everything and restarted it and it worked. Maybe there was something inbuffer throwing it off.

jmcorpse 0 Light Poster

That works, but it doesn't work inside the function that it is embedded in.

jmcorpse 0 Light Poster

Sorry it's on line 61 and 62.

jmcorpse 0 Light Poster

I wrote this program about four hours ago and everything but my if loop is working. I wrote a separate one in a test file and it works, for the life of me I can't get it to work in this program. When inputting anything other than a y or n it shuts down when it should ask for a valid input like y or n. Any help would be appreciated.

#include<iostream>
#include<cmath>
//Function declarations.
void getinput(double& feet,double& inches);//Asks for the input from the user.
void metconv(double feet,double inches,double& meters,double& cm);//The function that converts feet and inches to meters and centimeters.
void printOutput(double meters,double cm);//Prints out the data after the calculations have been made.
const double meters_per_foot = 0.3048;//Constant for meters in a foot.
char getResponse();//This will rerun or terminate the program based on the users input.

    using namespace std; 
    int main()
    {
    double feet,inches,meters,cm;//Variables for the program.
	char yes_no = 'y';//Variable for the response to rerun or terminate loop.
    do//Beginning of the do-while loop.
    {
	    getinput(feet,inches);//This displays the user prompts for the getinput function.
	    metconv(feet,inches,meters,cm);//This will display the information that is processed for the conversion function.
	    printOutput(meters,cm);//This is display the total meters and centimeters.
	    yes_no = getResponse();
        
    }while(yes_no == 'y');//End of the do-while loop.
	return 0;
    }
    
    void getinput(double& feet,double& inches)//This function gathers the needed requirments of feet and inches.
    {
        using namespace std; 
    	cout << "\nPlease enter the feet length: ";
	    cin  >> feet;//This will be used for thecalcultions.
	    cout << "\nPlease enter the inches length: "; …
jmcorpse 0 Light Poster

Thanks for your help, it's making sense to me now.

jmcorpse 0 Light Poster

Hello,

I have been working on this program for the past four hours and was doing good till I got to this point. I am pretty sure that I probably can't do it this way, but I'm just learning and it isn't becoming apparent to me how to correct it. Any help would be appreciated. I apologize in advance if the code wrap did not work properly.

#include<iostream>
#include<cmath>


//Global Variables and Function declarations

double bmr(double P);//BMR = Basal Metabolic rate. This function declaration is for the first function.
double pa(double intensity, double P, double time);//PA = Physical Activity. This function declaration is for the second function.
double eda(double fav_food);//EDA = Energy to Digest food. This function declaration is for the third function.
double mcw(double cals_con, double bmr, double pa, double eda);//MCW = Maintaining current weight. This function declaration is for the fourth function.

int main()
{
    using namespace std;
    char rerun;
    
  do
  {
//This is the section where the variables will be declared for the program.    

    double P;//P = pounds
    double intensity;
    double time;
    double cals_con;
    double servings;
   

//This is the prompt area asking the user for the information needed to operate the program.
    cout << "\n\nPlease enter your weight: ";
    cin  >> P;
    cout << "\nPlease enter the estimated intensity between 1 and 20 of your activity: ";
    cin  >> intensity; 
    cout << "\nPlease enter the amount of time (in minutes) spent doing your activity: ";
    cin  >> time;
    cout << "\nPlease enter the amount of …