C++ :: Logical Error In Output Of DAYNAME
Oct 31, 2014
I have to write a program that does the following: Monkey Business A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 - 7 array , where each row represents a different monkey and each column represents a different day of the week. The monkeys are represented by integers 1, 2, and 3; the weekdays are "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday". The program should first prompt the user to input the data for each monkey, starting with "Sunday" for monkey #1, then monkeys #2 and #3, followed by "Monday" for monkey #1, then monkeys #2 and #3 and so on, through "Saturday". The program then creates a report that includes the following information, each properly labeled (see below):
-Average amount of food eaten per day by the whole family of monkeys.
-The least amount of food eaten during the week by any one monkey.
-The greatest amount of food eaten during the week by any one monkey.
Input Validation: Do not accept negative numbers for pounds of food eaten. When a negative value is entered, the program outputs "invalid (negative) food quantity -- re-enter" and attempts to reread the value . Prompts And Output Labels: Decimal values should be displayed using default precision, i.e. do not specify precision. Each item read should be prompted for by a string of the form "Enter the food eaten by monkey #N on DAY:" when N is 1 or 2 or 3 and DAY is "Sunday" or "Monday" or ... or "Saturday".
The output should be of the form:
Average food consumed daily: 6.23
The least daily food consumed was by Monkey #0 on Friday
The most daily food consumed was by Monkey #2 on Sunday where the specific amount of food or specific monkeys or specific days identified depend on the actual input.
However after the process of resolving the errors unable to convert to standard string and unresolved externals I now have a logical error that causes the output of the DAYNAME variable to output as what appears to be hex in the following picture:
How I can fix this and why it's casting them as this in the output.
My full code is as follows because I don't know exactly, which line of code is causing this to happen:
Code:
//
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// constants
const int MONKEYS = 3;
const int DAYS = 7;
[Code] .....
View 5 Replies
May 11, 2013
I wrote this code to solve a problem in which the user inputs a permutation of size 'N' and the next permutation of the same elements has to be generated.
I went about this in this way: given 3 2 5 4 1, starting from the right, the first no. has to be searched which has a no. greater to it on its right. Here it is 2. Now an array is generated containing all no.s on its right and greater than it. For 2, it is: 5,4. Out of these the smallest member is searched for and switched with 2. So, 4 is switched with 2 to get the Next Permutation: 3 4 5 2 1.
The code I wrote does not show any error but does not return the correct value when run and gives the same value instead. If I enter '3 2 5 4 1' it returns the same value as the answer.
#include<iostream.h>
#include<conio.h>
void main() {
clrscr();
int N,M,i,n,c,swap,flag,count,small,m;
int Array[100],Key[100];
[Code] .....
View 2 Replies
View Related
Nov 15, 2013
My project is on an online shop in which you can manage a shop(adding ,deleting ,clearing and modifying items) also you can switch to different shops(all shops are same)
Code:
#include<iostream>
#include<fstream>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
[Code] ....
The logical problem is serious because i am not able to find the error!!! There is some problem with display lines in void shop()-->if(mode=='s') and if(mode=='d'). I add only one item but in output screen i see two items(sometimes >2)
*note* to run the above display lines in the output screen....first register--->add atleast one item--->see your shop
View 12 Replies
View Related
Jul 16, 2013
I've encountered a slight logical error in my code
/*
Lab06_pensionplans.cpp
Purpose :
- Create a simple financial application to calculate retirement plans
*/
#include <iostream>
#include <cstdlib>
using namespace std;
void displayMenu() {
system("cls");
[Code] ....
Look at case 2, which the user supposed to key in a new input, the problem is the value will never got into main function, I don't know what should I modify with the function.
Figured out I need to change the
void changeData(int startingAge, int numOfYears,
double lumpSumAmount, double yearlyAmount, double interestRate )
into
void changeData(int &startingAge, int &numOfYears,
double &lumpSumAmount, double &yearlyAmount, double &interestRate )
View 2 Replies
View Related
Dec 20, 2013
I wrote this program using an online compiler i am getting a lot of errors.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
string birthmonth;
string birthday;
[Code] ....
View 6 Replies
View Related
Jul 26, 2012
I have a question related to switch statement, which the switch in class employee2 gives me error at output. Program compiled well. I am using Code::Block Compiler V10.5. I have created object of class employee2 in main() function to get data from user, store it and display it. At the output, Compiler doesn't show actual output what i am expecting. The fun thing is my compiler printed emocion like (), where (hourly/monthly/weekly) was supposed to print.
Code:
#include <iostream>
using namespace std;
enum period {hourly,weekly,monthly};
class employee2 {
private :
char ch;
period x;
double compensation;
[Code] ....
View 10 Replies
View Related
Mar 9, 2013
I've received a segmentation fault in this part of code:
Code:
for (; str[i] != '