C++ :: code Fails Due To Large Input
Jan 25, 2015
So the question is this [URL] .....
My code is this:
#include <iostream>
#include<cmath>
using namespace std;
int main(int argc, char *argv[]) {
long double div;
//div=((1e+9)+7);
[Code] .....
The problem is when the hackerrank inputs the following:
10
5351871996120528
2248813659738258
2494359640703601
6044763399160734
3271269997212342
4276346434761561
2372239019637533
5624204919070546
9493965694520825
8629828692375133
My code gives the wrong output.
The output is supposed to be
578351320
404664464
20752136
999516029
743537718
323730244
174995256
593331567
136582381
305527433
So what changes should I make to get my code give the correct output.
View 9 Replies
ADVERTISEMENT
Feb 11, 2013
Is there a quick shortcut (like CTRL+something) to comment out/ decomment a large block of code in Dev C++ when it is selected?
I find it tedious to go line by line and add the // in front of each line.
View 3 Replies
View Related
Nov 7, 2014
I am writing a spell checker for a exercise for a class I am taking online. I have to load a huge text file of 143092 words into a hash table.
The program segfaults on word number 63197. Is there a way to debug this in gdb without having to step threw the function 63197 times.
View 3 Replies
View Related
May 12, 2014
I need to convert some input values in c#
for example if input is 0.0 then it should take value as 63.
0.5 as 62
1.0 as 61
1.5 as 60
2.0 as 59
2.5 as 58
3.0 as 57
:
:
:
:
28.5 as 3
29.0 as 2
29.5 as 1
30.0 as 0
now maybe I can define it in enum and use it but before doing that i wanna try if i can put an equation instead of defining these values into memory.
View 2 Replies
View Related
Feb 10, 2013
So I have to write a code for my C++ class, and I am having a problem trying to figure out how to get my code to read multiple int values. This is what my code should look like
Enter two times in military format (e.g., 1730 1520): 1730 1520
[1520<1730]
Enter two times in military format (e.g., 1730 1520): 1520 1730
[1520<1730]
Enter two times in military format (e.g., 1730 1520): 1730 1730
[1730==1730]
Enter two times in military format (e.g., 1730 1520): 1760 1520
1760: [INVALID TIME 1]
Enter two times in military format (e.g., 1730 1520): twelve 2
[INVALID NUMERIC INPUT]
View 1 Replies
View Related
Nov 22, 2013
at the moment my program is extracting keyboard data through accessing the virtual key states. However, it is not performing as I intended because the data I receive from the console does not concur with the actions the user performed.
E.G. When I type, it comes out like this.
what I get with my program: WWhhhheeen III typeeee, iiit ccoommes oout lllikkke thhhhiiis
TLDR: so basically Id like to know how other programs know how to interpret keyboard input, so that when I type I dont get multiple inputs of the same key press
View 2 Replies
View Related
Nov 5, 2014
This program gets input from a file and output to the screen and to a file. The difficulty I am having is summing the number I retrieve from the file for the individual numbers of sightings.
#include <fstream> // enables us to read and write files
#include <iostream> // for cin and cout
#include <cstdlib>
#include <string> // enables us to hold strings of characters
#include <cctype>
using namespace std;
[code].....
View 14 Replies
View Related
Sep 18, 2013
I am in the process of writing a program that will give the appropriate color code for a resistor after the user enters an integer value for the resistance needed and selects the tolerance form a list. My question is this: Is there a way to allow the user to enter a value such as 75000 and C++ use each digit separately, as if they entered 7 [enter], 5[enter], 0 [eneter]... and so on? But, then use the entire value as an integer too? Also, it should read a value such as: 45835, as 45000, or 1843 as 1800.
View 1 Replies
View Related
Feb 20, 2014
I have made a program that converts or reverses an input string. Here is my code working fine
static void Main(string[] args){
string input = Console.ReadLine();
string[] words = input.Split(' ')
for (int i = words.Length; i > 0; i--)
Console.Write(words[i - 1] + " ");
Console.WriteLine();
Console.ReadLine();
}
How can I write this program in pseudo code?
View 2 Replies
View Related
Jan 12, 2015
I`ve wrote a function for my utility to XOR char* buffer by a key, then to reverse it with the same key. Here is the code, it`s simple enough:
Code:
static inline char* XOR_buffer(const char* d, const char* k ) {
char *newstr = (char*) malloc(sizeof(char)* strlen(d));
newstr[0]='';
printf("%d is size of string
", strlen(d));
char *begin = newstr;
char* ret = begin;
int len = strlen(k);
}
[code]....
The lengh of the string is reduced by the second XOR call. You can try it out, just define XORDBG to view the error message in the second pass to the buffer.
View 9 Replies
View Related
May 29, 2013
i created an com client that try to create com server with the command CreateInstance. at win 7 it works fine (both 32 and 64 bit). but with xp it fails. i created the app with win 7 - 64 bit.
View 14 Replies
View Related
Oct 6, 2014
cin returns fail on trying to read double value.
Code:
#include<iostream>
#include<array>
using namespace std;
const int MAX = 10;
void read_donations(array<double, MAX>& a, int& count);
int main()
[Code] ....
View 4 Replies
View Related
Jan 2, 2015
I am creating a special struct with unknown functions. I use this approach:
Callbacks.h Code: #ifndef CALLBACKS
#define CALLBACKS
struct Callbacks;
struct Callbacks* getNewCallback();
[Code]....
When I ran it only the calls from doers array is called 7 times normally, and donters only one time. Why is that? When I call doers from the second loop, it prints the doers functions again....and only one call to donters is made to the first static inline donter functions __dont1()...
View 7 Replies
View Related
Nov 3, 2013
What I have is a main function that takes input characters from the command prompt during the main function call, and coverts it to an integer array a using atoi. (starting at the 2nd character - the 1st is reserved for another call that I plan to reference later, and the 0th is obviously the ./function). A function is then called to find the mode of an array (the range of values in the array is 1-30). Now, when I run the whole thing, I get a segmentation fault (core dumped) for even number of arguments. It's late and I've been staring at it for too long...
Code:
#include <stdio.h>
#include <stdlib.h>
int get_mode(int a[], int count);
[Code]......
View 1 Replies
View Related
Mar 29, 2014
I'm trying to write a piece of code that calculates the difference in days between two manually input dates. The part of my code that's causing problems is:
xxx
When running the code and prompted to enter the date, if I input for example 31/12/2014, it'll be rejected and send me back to the beginning of the loop. Any date with 31 days involving months 1, 3, 5, 7, 8, 10 or 12 causes this problem. All other valid dates however work perfectly fine (e.g. 30/4/2014).
Something possibly worth mentioning is that, when I take out all other conditions from the loop, i.e.
xxx
it works fine (31/12/2014 is accepted), but of course I need all of the other conditions in there too.
View 1 Replies
View Related
Apr 13, 2014
I have a quick question about dynamic memory. I know that if you are dynamically allocating memory for a single data array and it fails, you can immediately abort the program via a return statement, but is this also true with multiple data arrays? For instance:
int *foo, *bar
foo = new (nothrow) int [5];
bar = new (nothrow) int [5];
if (foo == nullptr || bar == nullptr)
return -1;
else
/*rest of execution */
If the answer to the previous question is no, do you need to do a delete[] on the arrays that succeeded before terminating the application? Say foo is correctly allocated but bar fails, would you have to do something like this?
int *foo, *bar
foo = new (nothrow) int [5];
bar = new (nothrow) int [5];
if (foo == nullptr || bar == nullptr) {
if (foo == nullptr && bar != nullptr)
delete[] bar;
[Code] .....
View 4 Replies
View Related
Feb 4, 2015
I'm trying to write a wrapper for rapidXML in order to use it in my projects however I've run into a curious bug that's preventing me from properly saving the XML documents I'm working with. The gist of it is: simply parsing a very simple xml doc and then saving the same document to the same file (without modifying it) creates a mostly correct output except for scrambling a few node closures:
bool rXMLwrapper::parse(){
try{
std::ifstream file(filepath.c_str());
if(!file.is_open()){throw std::bad_alloc();}
std::stringstream buffer;
buffer << file.rdbuf();
file.close();
[code]....
I'm using this patch for rapidXML: [URL]
As a foot note: I'm almost certain it's not an issue with the parse() function.
If I parse() the document and then call std::cout<<doc; it prints the document perfectly fine to the console, but for some reason std::ofstream<<doc; causes issues.
View 1 Replies
View Related
Jan 27, 2012
Why I'm getting an error here. I've dumbed down my code for simplicity and removed irrelevant code.
PHP Code:
class Foo {
public:
bool IsNull() const;
private:
std::map<int, int*> test;
[Code] ....
I'm getting a "passing...discards qualifiers" error on my if statement and not sure why because I'm not changing anything. I know removing const or making test mutable fixes the issue. I've been taught to always make a function const if it doesn't change anything, in which case, have I finally come across an acceptable time to use mutable?
View 9 Replies
View Related
May 17, 2014
The code is supposed to display the total and averages of the data as well, but cuts off due to an error in the code. The code should also:
1)Print checks for all employees, one per page, sorted by lastname. The first check number, 100, is to be read from a company data file (see requirement 4). The border of each check is important and should not be omitted.
2)Convert the net pay to a text string for each check printed.
3)Print a reference code on each check. The reference code is obtained by combining the first letter of the lastname with all the consonants remaining after removing all vowels (a,e,i,o,u).
4)Use the same employee data found in assignment 2. Use the following company data, obtained from a text file,
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
[code]....
And here's where the program stops. URL.....
Output I'm expecting: Program to display totals and averages (worked before I turned everything into an array), now exits with error before totals/averages are displayed. Program also writes up a report.txt file that also writes this information into it, as well as using a quicksort to organize the names alphabetically, and print paychecks (all of the #BORDER, #HEADER1-8, #STUB, etc). In that check a reference code is also generated (teacher gave us code, we just had to modify for our final program as seen here)
Flow of the program: Print headings to label all of the input data we will enter soon under the categories as listed in the heading. Initialize all of our totals (in our array) to value of 0. These will be added in a loop "AddAccumulators" which takes our value for the hours, payrate, and taxes from each employee array structure and adds it to the total array. Program will write this information into the report.txt file with the HEADER line for totals, and should be displaying it in that picture. (Same for averages). After all of the data is calculated, the Reference code, Totals, Averages, and individual employee data is taken and put into printing out a Check Header and Stub.
View 10 Replies
View Related
Dec 9, 2013
How do i display the output ? This program only saves the output to "gpa.txt" I want it to also display the output to cmd.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <string>
using namespace std;
const int SIZE = 10;
[Code] ....
View 1 Replies
View Related
Jun 23, 2014
I have this proxy class generated from a webservice:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="java:se.atg.aisbean.calendar")]
public partial class RaceDayCalendarSimple : object, System.ComponentModel.INotifyPropertyChanged {
[Code] ....
I'm trying to access this method "RaceDaySimple[] raceDay" and display it on "WebForm1.aspx":
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebServiceClient.WebForm1" %>
<!DOCTYPE html>
[Code] ....
So on "WebForm1.aspx.cs" I'm trying to access the method "RaceDaySimple[] raceDay" and display it inside the div "test":
test.InnerHtml = pbs.fetchRaceDayCalendarSimple().raceDay;
But I'm getting the error:
Cannot implicitly convert 'WebServiceClient.InformationServiceReference.RaceDaySimple[]' to 'String'
So how do I acces this method proparly and display the content on "WebForm1.aspx" inside the div "test"?
View 1 Replies
View Related
Dec 27, 2012
I have some problem while allocating memory to a union inside structure. Below is the code i am using
ON SYSTEM1:
This works fine
ON SYSTEM2:
compiler complains saying "need structure or union type" while allocating MYSTRUCT1.
If I change:
shreyas[0].UnionAttr.struct1 = (MYSTRUCT1 *) malloc (sizeof(MYSTRUCT1)
to
shreyas[0].UnionAttr->struct1 = (MYSTRUCT1 *) malloc (sizeof(MYSTRUCT1)
This compiler on SYSTEM2 is happy. but second way does not look correct to me and compiler on system 1 complains about it. Which is the correct way to allocate memory?
If first one is correct then what should i look in for to avoid this error? Could this be an issue with compiler on SYSTEM2? If i use second method on SYSTEM2 code segfaults during malloc.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct mystruct1 {
int a;
int b;
[Code] ....
View 3 Replies
View Related
Jan 24, 2014
Background: I'm using SDL and CodeBlocks and trying to make a Graphics class that would simplify some SDL operations such as drawing and loading images.
Issue: The loadImage function in the graphics class fails to load the image correctly and so the program prints out a blank window during run-time. I've tried multiple ways of passing a string literal into the function the surface temp fails to load and so background in Game fails to load. After testing it several times, I'm pretty sure that the issue lies with SDL_LoadBMP not registering the passed variable for whatever reason. I know the image is in the right place as writing SDL_LoadBMP("./Graphics/image.bmp"); brings it up just fine.
Current Code:
Main simply creates a Game object and execute(), so I didn't feel the need to put it on here.
Game.h
#ifndef GAME_H
#define GAME_H
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#include "Graphics.h"
#include <string>
#include <cstring>
using namespace std;
//GLOBAL CONSTANTS
//game window settings
[Code] ....
Output: A blank window. (It should show the background image but doesn't.)
Note: I originally wrote it as gfx.loadImage(background, "./Graphics/image.bmp") but that gives me a conversion warning and still fails to show the image when the program runs. I've tried looking up examples similar to what I was doing but no one else seems to have this problem.
View 3 Replies
View Related
Feb 28, 2015
I am getting some weird errors while building in release mode. It works fine in debug mode. Libraries and includes are linked in both debug and release version, but it's acting like it's not.
main.cpp
#define GLEW_STATIC
#include <glew.h>
[Code].....
View 2 Replies
View Related
May 17, 2014
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
[Code]....
I know it has to do with the array, and I've tried over and over again to fix my issue and nothing has worked thus far.
View 3 Replies
View Related
Apr 29, 2014
I have a very strange problem with the system() function (on XP).
I have the following code:
Code:
char *text1 = ""A SpaceAction.bat" fred";
char *text2 = ""A SpaceAction.bat" "fred"";
int main(int argc, char *argv[]) {
printf("%s
", text1);
[Code] .....
When I run it where "A Space" is a directory with a space in the name, this is the result:
Code:
"A SpaceAction.bat" fred
F:Test>echo Testing
Testing
"A SpaceAction.bat" "fred"
'A' is not recognized as an internal or external command, operable program or batch file.
It seems that the double quotes round an argument make the parsing of the command fail.
View 1 Replies
View Related