C++ :: Printing Too Many Times To The Screen
Mar 29, 2013
I've got most of the program to work but its printing to the screen 5 times and I only want it to print once.
Eg:
cos1512: 57.00%
mat1512: 86.50%
inf1520: 65.10%
cos1521: 78.40%
inf1505: 89.10%
but I get:
Semester Marks:
================
cos1512: 57.00%
mat1512: 57.00%
inf1520: 57.00%
cos1521: 57.00%
inf1505: 57.00%
cos1512: 86.50%
.....
My code:
#include <iostream>
using namespace std;
class Module {
public:
void setModules(string module1, string module2, string module3, string module4, string module5);
void setMarks(int aMark1, int aMark2);
int updateMarks();
[Code] .....
View 4 Replies
ADVERTISEMENT
Sep 20, 2013
I want to have one case of my switch statement to print out how many times the user has chosen other cases in the switch statement. Such as "You have pressed 2 6 times and 4 3 times."
View 3 Replies
View Related
Jan 9, 2015
how to make a program in which a user is prompted to input four numbers like 1234 and then print those four numbers one by one on screen using only one variable..??
For example:
1
2
3
4
in ascending order...
I've done that with two methods but i am not sure whether the methods were correct..
View 1 Replies
View Related
Mar 24, 2013
I have a linear buffer coordinate, i am to print onto a screen coordinate.
Say maxy = 20, maxx = 10, bufferx = 20, y, x,
Buffer coordinates to screen coordinates:
Algorithm: So for each maxx'th of bufferx, y will +1 and x will reset.
Mathematical: y = int bufferx / maxx,
const double averageIncr = int (maxx+1/maxx) - double (maxx+1/maxx);
So the amount of averageIncr in (int bufferx / maxx - float bufferx / maxx)
is the screen x coordinate. Then
(int bufferx / maxx - float bufferx / maxx) / averageIncr = x
Screen coordinates to buffer coordinates:
bufferx, y = 21, x = 10, maxy = 20, maxx = 10,
y * x would be the case if bufferx <= max screen coordinate.
There is no max bufferx.
How to find the transition from screen coordinates to buffer coordinates? Also, if the algorithm within a for loop, or that the mathematical way would be slower or not? I rarely touch floating point stuff.
View 3 Replies
View Related
Oct 29, 2013
I have been trying to make a program that asks for username and password, and if it is wrong it will loop back to the top. But i only want it to loop a set number of times, how can i do this? This is my code so far
string username;
string password;
cout << "Enter username: ";
getline(cin, username, '
[Code] ....
View 4 Replies
View Related
Sep 15, 2013
I was wondering that why in the below code, the copy constructor is called 2 times.
Code:
class A {
private:
static int count;
int age;
public:
A()
[code].....
I think that when f(a) is called, since I am passing this as value, no copy constructor should be called. The copy constructor should called when the return object "x" is assigned to:
A b = x;
why copy constructor called 2 times?
View 9 Replies
View Related
Apr 5, 2014
so i have to read a text file with an unknown number of lines and allocate memory to for the number of items in the text file.currently i read the entire file(counting the number of lines). i allocate memory according to the number of lines read and then use fseek() with an offset of zero to allow for the second read .
View 5 Replies
View Related
Aug 6, 2013
I create a loop that would repeat itself many times a second? Trying to do extremely basic graphics with a grid and system("cls") every time I run a command, but it still looks very jumpy. I realize system calls are evil. Any way to get rid of this too.
View 1 Replies
View Related
Sep 7, 2014
I have a question about SDL and drawing sprites (SDL surfaces). My idea is that the user can create a wall of separate sprites by create one sprite each time in the current mouseX and mouseY position, when the user push down the e-key. The problem is that I have no idea how I could draw the same sprite multiple times without to delete the previous one.
View 3 Replies
View Related
Feb 20, 2015
I'm trying to create a program that loops "x" number of times, where "x" is going to be a user-input number.
View 2 Replies
View Related
Jul 28, 2014
This is part of the program, What should i do if i want to total the number of times a shape was selected at the end?
#include<iostream>
#include<string>
#include<iomanip>
[Code]....
View 3 Replies
View Related
Apr 4, 2014
Actually whats the size of the stack and we can increase the size?
View 1 Replies
View Related
May 10, 2012
How can we use switch statement 2 times in a program?
View 2 Replies
View Related
Jan 12, 2012
I hope I got all the jargon correct. I have something like this:
Code:
const Fl_Color my_fl_dark_gray=fl_color_cube(64*(FL_NUM_RED-1)/255, 64*(FL_NUM_GREEN-1)/255, 64*(FL_NUM_BLUE-1)/255);
in a header file and the header file is included in several C files.
Questions:
At run time,
Is there just one copy of the const variable my_fl_dark_gray or are there multiple copies for the multiple C files?If a function uses the const variable, does the initialization statement "my_fl_dark_gray=fl_color_cube(...);" run every time the function is called or does it just run once and then when the function is called it just uses the value stored in memory?
View 9 Replies
View Related
Mar 17, 2014
This is the problem:
1+2+3+...+n=(n(n+1))/2
Write a C++ program that compares the execution time of the above summation using two different solutions: one that uses loops, and another that uses the closed form approach. Use large values of n for the comparisons, such as, 10^7, 10^8, 10^9, 10^10, 10^11,10^12, 10^13, and 10^14. Provide a comparison table for the execution time in both solutions.Do not worry about the value of the actual sum. Overflow will occur in the sum value rendering it invalid; however, this is not the primary concern of the program. Execution time is the primary concern.
View 1 Replies
View Related
Jan 27, 2015
Assume all variable are declared correctly, the following for loop executes how many times?
for (i = 0; i <= 20; i++)
cout << I;
I think 20 but am not sure.
View 7 Replies
View Related
Feb 1, 2013
Be given a string of chars, where each single char belongs to the following alphabet: a..zA..Z0..9 (So, in the string there are only lowercases, uppercases and digits. No blank, no comma, ...).
For every char of the given alphabet, count how many times in the string
1----- the char is preceded by its predecessor in the alphabet (consider that the predecessor of 'a' is '9')
2----- the char is followed by its successor in the alphabet (consider that the successor of '9' is 'a')
3----- the char belong to a sequence of identical chars whose length is at least three (i.e.: in the string cc74uyrpfccc348fhsjcccc3848djccccc484jd for three times the character 'c' satisfies this condition)
4----- what is the longest substring of characters strictly rising (the following is greater (>) of the previous)
5----- what is the longest substring of successive characters (i.e.: fhkjshdfruytyzABCDEfglsj => 7)
6----- the frequencies of any char (if in the string the character 'g' occurs 12 times, its frequency is 12)
View 5 Replies
View Related
Dec 24, 2013
How can I check how many times the numbers in the array are listed?
View 2 Replies
View Related
Sep 15, 2014
I've been stuck on this for hours, and have scoured the internet for any insight on this particular issue with no luck.
I'll simplify the problem here. I have a lines in an input file:
John Smith 1234 Main St New York
Carol Thomas 5678 5th Ave Columbus
...
and I am reading into character arrays using code like this:
infile.getline(name,20);
infile.getline(street,15);
infile.getline(city,10);
but when I print the output using something like this:
outfile << "Owner Name: " << name << endl;
outfile << "Address: " << street << city << endl;
(let's pretend I included spaces between the address components, which I omitted to save space)
I get an output file of:
Owner Name: John Smith
Address:
The output stops after the name variable, which I believe is stored correctly. I don't think anything is storing in the address pieces, this is the problem.
I think it's because I'm not using getline() properly in this case. Can you string together multiple getline()s like that?
If this was my design, I'd read in strings instead, but that is not possible in this case.
View 6 Replies
View Related
Nov 28, 2014
I tried my best but I can't figure out the problem. At the last part of "createArray", I output the final array created. I mean it to repeat once but then it repeat more times than I expect. createArray is an iterative function. If it repeats 3 times, than at last the array created which fulfil the criterion would be printed out 3+1 times.
I am trying to create an array with 3 numbers 5 times, resulting in a 2D array. The 3 numbers in a array are picked from 0 - 5. I enter createArray(5,3,5). Then these 5 arrays are compared with each other to see if there are repetitions. If there are, the whole process begins again, 5 arrays with 3 numbers each will be picked again and compared with each other. If there are no repetitions at last, there 5 arrays would be printed out.
void deleteArray(int** array){
delete[] array;
}
int** createArray(int simu_times, int randomrun,int numberofrun){
vector<Int_t>fChosenRun;
int** Array = new int*[simu_times];
[Code] ....
View 8 Replies
View Related
Sep 19, 2014
I've been working on a program that uses a reference counting class that I've written which works fine for objects that inherit from it however I now need to have the following setup:
class SBComponent : private Refcounted { /*stuff*/}
class ProxiedComponent : public SBComponent, private Refcounted {/*stuff*/}
The compiler gives the following warnings
warning: direct base ‘Refcounted’ inaccessible in ‘ProxiedComponent’ due to ambiguity
And then several repeats of the error:
error: request for member ‘bk’ is ambiguous
Back *b = bk<ProxiedComponent>();
bk is a templated function that's defined in Refcounted and returns a pointer of type <template arg>::Back (ProxiedComponent::Back in this case).
I don't understand why the call to bk is ambiguous as although there's two instances of Refcounted (there needs to be with the way I've designed it so I can't make it virtual) it's inheritance is private in both cases so there should only be one instance of it visible in ProxiedComponent.
View 7 Replies
View Related
Nov 6, 2014
I've been struggling with an object when trying to add it to a list with [Listname].push_back. You see, I have a list with some objects that will be rendered in the screen (Called objects) and a function to create a text box with some text. The function in question is the following:
void reprEv(int evNum, ALLEGRO_BITMAP *txtbxim) //Event to call, default text box image.
{
textBox *txtBox = new textBox("Line 1 ", "Line 2 ", "Line 3 ", "Line 4 ", "Line 5 ", textboximage);
objects.push_back(txtBox);
[Code]....
(txtNum is increased then space is pressed, and when certain screen (maxScreen) have been shown, then it will go to the playing state)
My problem begins when the text box is created, because it's supposed to add only 1 text box to objects list, but instead adds hundreds of text boxes to objects.
View 1 Replies
View Related
Mar 17, 2015
I want to write how many times a method is called. The first class houses a method that I want to count from the second class how many times it is called. what I am able to achieve so far is that it only writes out how many times it is called but what I want is that it should be like a counter like this: if called ofr 5 times it should print:
1
2
3
4
5
and not just 5.
First class
public static int count = 0;
public void Login(String LoginUsername, String LoginPassword) {
count++;
}
Second class
int i = LoginReusables.count;
i++;
System.IO.File.WriteAllText(@"C:Usersken4wardDesktopTidyWriteLines.txt", i.ToString());
View 11 Replies
View Related
Nov 13, 2014
I suspect it is a logical error but I can't pinpoint it. The assignment is to input a time of day in 24 hour format, pattern match with scanf, and print out the closest arrival and departure times for that time. The arrival and departure times are in minutes past midnight in a constant array. I am getting no bugs but the program is not giving correct values.
/* filename: hw25.c
* Purpose: Finds the closest arrival and departure times
*/
#include <stdio.h>
#include <stdlib.h>
#define N 8
#define HOUR 60
void find_closest_flight(int desired_time, int *departure_time, int *arrival_time);
[code]....
View 11 Replies
View Related
Oct 19, 2012
I need to make a program which solove difference between two interested times in format hh:mm i made it but it doesn't give me right answers for all times for example it can't solve times like 23:50 and 0:15 and it says that difference is 23:35 and no 00:25
View 3 Replies
View Related
Jun 8, 2014
Repeat the vowel Problem 3 (0 / 0)Write a program that will repeat k times each single occurrence of a vowel in the input file "sp.txt" to a new file "output.txt". The first line of the input file contains only the parameter k. The first line (containing the parameter k) should not to be written in the output file.
I wrote the code but i cant figure out something. i read the file, i found the vowels but then i cant print them.
Code:
#include <stdio.h>#include <string.h>
#include <ctype.h>
#define MAX 100
int checkvowel(char c)
[Code].....
View 6 Replies
View Related