C++ :: Program That Asks User For Numbers And Adds Odd Ones Doesn't Work

Nov 12, 2014

Title is self-explanatory.

Code:
#include <iostream>
using namespace std;
int main ( ) {
float number;
float sum;
float divi;
while(number != -1) {

[Code] .....

View 5 Replies


ADVERTISEMENT

C/C++ :: Write A Program That Adds Numbers To Array

Jan 18, 2015

I am trying to write a program that adds numbers to an array. The array capacity starts out at 2, then doubles whenever the size reaches capacity. The program works perfectly fine when the array needs to be expanded. So I have narrowed down the issues into this one function (_dynArrSetCapacity)

Creates original array
DynArr* createDynArr(int cap) {
assert(cap > 0);
DynArr *r = (DynArr *)malloc(sizeof( DynArr));
assert(r != 0);
initDynArr(r,cap);

[Code]...

If i do createDynArr(10) for instance in the main, the program works perfectly, as it never gets expanded

View 3 Replies View Related

C++ :: Write A Program That Asks The User For A Name

Jul 2, 2014

So I am trying to write a program that asks the user for a name. If the user enter the right name the program ends but if the user were to enter the wrong name the program would enter a loop prompting the user to re-enter the name. However I am not able to get the program to work!

View 9 Replies View Related

C :: Make Program That Asks User For Number?

Oct 15, 2013

So I'm trying to make a program that asks the user for a number and then prints a statement the same number of times the user entered. 3 different statements, using the 3 loops (for, while, and do while). I made the program but for some reason the statement from the do while loop goes off infinitely.

MY CODE:

The error:

View 8 Replies View Related

C++ :: Program That Asks User To Enter Even Number Only

Mar 23, 2014

Write a C++ program that asks the user to enter an even number only. If the user enters an odd number the program should use input validation to ask the user to enter another number.

- The user can enter as many numbers as he wants

- The program should also keep a count of how many numbers entered and display how many odd and even numbers entered.

View 1 Replies View Related

C/C++ :: Write A Program Where It Asks The User For A File Name?

Apr 18, 2014

I'm trying to write a program where it asks the user for a file name.

If that file exists, the it will open the file and then read it and print the information in the file.

However, if the user enters a file name that does not exist, the user will have 2 more tries (for a total of 3 tries) to get the correct name of the file.

I am close to getting it. What I have now just won't go through the loop to validate if the input matches an existing file. It goes straight to the printing of what is in the file. If the file doesn't exist, it prints: "Found your file..Opening..processing...Total keys found = 0."

So, my question, what am I doing wrong that it won't go through the loop properly?

#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
int main() {
bool fileFound = false;

[code]....

View 2 Replies View Related

C :: Program That Asks The User To Type 10 Integers Of Array?

Mar 2, 2014

Write a program that asks the user to type 10 integers of an array. The program will then display either "the array is growing", "the array is decreasing", "the array is constant", or "the array is growing and decreasing."

(Hint: compare consecutive numbers in array and check whether it is increasing or not or constant) I wrote the program very well, but do I have to use "bool" like in c++ ? I haven't known how to code in c++ yet.So, I don't want to use "bool" in C.

I also wrote code about it but it looks like backslash and one,two,three,four,five how can I do it like this ?

View 4 Replies View Related

C++ :: Program That Asks User To Prompt Integer Number

Nov 18, 2013

Write a program that asks the user to prompt an Integer number and then test whether it is Palindrome Numbers or not.

The following are Palindrome numbers:
1.22
2.333
3.67876
4.44444
5.123454321

View 8 Replies View Related

C++ :: Writing Program That Asks User To Input Number?

Sep 11, 2013

im writing a program that asks the user to input a number 1-10 and will transform it into the roman numeral of that number but it seems that its not after the user inouts the number nothing will output

#include <iostream>
#include<iomanip>
using namespace std;

[Code]....

View 3 Replies View Related

C++ :: Write Program That Asks User To Enter Student Grades?

Jan 21, 2014

Write a program that asks the user to enter a student’s grades on four exams. The program should display the four grades and the average of the four grades,rounded to the nearest tenth. To add the grades, use a variable called total_grade, which you should initialize to zero.As the program prompts for and obtains each grade, add the grade to total_grade using the += operator.

View 3 Replies View Related

C :: Create A Program That Asks User To Input Integer Lengths Of Three Sides Of A Triangle

Sep 6, 2013

C programming: I want to creat a program that asks the user to input the integer lengths of three sides of a triangle, and if so whether the triangle is a right-angled, acute or obtuse one. i am having some doubts about the if, else if statements. I never seem to know how and in what order to use them.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[]){
int SideA;
int SideB;
int SideC;
}

[code]....

View 14 Replies View Related

C++ :: Enter As Many Numbers Until User Doesn't Type E To Exit

Oct 27, 2013

Enter as many numbers as you want as long as the user doesn't type 'e' to exit.

Problem: When I enter a number, it works fine, but if I enter e then it'll go in an infinite loop since the letter is being stored in an int variable. How can I (when I press 'e') make it convert to a char to make it end the program?

#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number or press e to exit:";

[Code] ....

Our class has just started c++ and we have not learned arrays and classes yet, so I'm guessing there is a way to do this without it? Or no?

View 2 Replies View Related

C :: Calendar Doesn't Work

Sep 24, 2013

I just dont see what the issue is here. I have stared at this thing forever. Im trying to make a calendar from scratch so I can be prepared for my second test on Friday.

Code:
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i, n, s;

[Code]....

View 10 Replies View Related

C++ :: Do While Statement Doesn't Work

Nov 21, 2013

#include <iostream>
#include <string>
using namespace std ;
int main() {
string bored ;
do {
cout << " program" <<endl ;

[Code] .....

I made this as a simple do/while program, and if i run it, the second do/while statement will keep on going forever, without the [cin >> bored;] line working?

View 2 Replies View Related

C++ :: QuickSort Code Doesn't Work

Jun 9, 2014

I've implemented it a bit differently: I create 2 temporary arrays, one for the numbers lower from the pivot , an done for numbers greater then the pivot. in the end of each iteration the 2 arrays are copied to the original array:

Code: #include <iostream>
void QuickSort (int* A , int start, int end){
if (end-start<3){
return;
}
int mid=(start+end)/2;
int pivot=A[mid];
int lA[end-start] , rA[end-start], rCounter=0,lCounter=0;
int curr=0,i=start;

[code]....

View 3 Replies View Related

C++ :: Application Release Doesn't Work On Other PC

Dec 9, 2013

I am trying to release my C++ app to run on desktops that dont have VS installed and have created an install shield app to install on the desired computer. my issue is even after packaging it, it still requires certain DLL's...I read online that I had to copy 'msvcr120.dll' and a few others to syswow64 and sys32 folders but now when I try run my app it just crashes before starting.

I think it sucks that Microsoft no longer packages required DLL's like it used to in 2010.

View 1 Replies View Related

C/C++ :: Code For Bin File Doesn't Work

May 14, 2014

Ive been having a hard time creating bin file. Whenever I append data, the data wont show in browse function. And this program works good without the bin file code.

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

[Code]....

View 2 Replies View Related

C++ :: Text For Score And Difficulty Doesn't Seem To Work

Sep 28, 2013

my text for the score and difficulty doesn't seem to work. They are both appearing twice and not updating. The score text worked fine until I inserted the difficulty text and I can't seem to find the problem. URL.....

#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <SFML/Graphics.hpp>
int main()
{
sf::ContextSettings settings;
//settings.antialiasingLevel = 8;

[code]....

View 2 Replies View Related

C/C++ :: String Copy Into Struct Doesn't Work

Nov 1, 2012

i'm right now using C, IO is done via ncurses, but that won't affect the following problem, i think. The relevant code is:

#define SIDEBARWIDTH 27
//...
typedef struct {

[Code]...

surprisingly this works, now the new 3rd outputline is correct again. So it seems that the printcommand has some troubles with accessing the struct here. Not sure if that might be ncurses fault. Still feels odd.

View 2 Replies View Related

C++ :: Increase Char Code Doesn't Work

Jun 11, 2014

Code:

#include <iostream>
using namespace std;
int main () {
char character = 'a';

[Code] .....

the point of this code is to increase character by 1 (so from a to b in this case).

The line highligted in red is the line that the system is rejecting at the moment (but there may be other issues). why it is invalid?

View 5 Replies View Related

C :: Laser Project Tile Engine Doesn't Work

Aug 27, 2013

I should reduce the number of bitmaps I used in my code. I translated my particle engine into code that could be compiled as plain standard C

Currently, the code has a segmentation fault somewhere that I can't figure out. How it should function is that it takes orders from a queue for new lasers to store the instances in a linked list. It then takes that data and updates its coordinates, one node at a time. The first node should also be the first node to complete its life, so it gets removed, and the list is set to the next node in memory. If there are no more nodes left, a if-statement should catch it and either break the current loop, or wait for more items to be requested. If there are nodes left, the process will continue to remove the first node in the list until there are none left. Obviously this is not quite how it works. When I tested in once in SDL, the laser would update every 5 frames, but wasn't shown constantly, and would crash after the node was to be disposed of. When I initialize with the SDL parachute, it would exit before I event saw the screen. Also, the code I translated to standard C will display that the laser has been updated to the screen, but it never says that it has moved up. It crashes after about 4 printf() statments execute. My debugger has been giving me mixed SIGTRAPS, and "nothing is wrong" output. Here is the code in standard C:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX_LASER_QUEUE 10
}

[code]....

View 6 Replies View Related

C++ :: Fstream Doesn't Work In Combination With Linked Lists

Jan 1, 2014

Im about to program a RPG and, of course, the player has got an inventory. The items in this inventory are stored in a linked list and have IDs in form of strings.

player.cpp: (just the most relevant)

#include <list>
#include <string>
using namespace std;

[Code] ....

Of course, when the player saves the game, the inventory has to be saved too.

game.cpp(just the m. R.)
#include <fstream>
using namespace std;
class CGame{

[Code] .....

Now, in my code I write the linked list into the file savegames.sav

void CGame::save(CPlayer* player){
m_out.open("savegames.sav", ios::out);
m_out.write((char* ) &player->m_inventory, sizeof(player->m_inventory));
m_out.close();
}

In another function i load the list:

void CGame::load(CPlayer* player){
m_in.open("savegames.sav", ios::in);
m_in.read((char* ) player->m_inventory, sizeof(player->m_inventory));
m_in.read();
}

And when i access the loaded linked list with the .empty() function or so, Windows says the following:

<Mygame.exe> funktioniert nicht mehr (in English: doesnt run anymore).

I tried so much to fix that but i dint reach my aim.

View 2 Replies View Related

C++ :: Matrix Class - Template Constructor Doesn't Work So Well

Feb 5, 2013

I realized a Matrix class to practice and I have a problem I can not solve! Here my problematic code:

Mtrx.h:

Code:
template <class T>
Mtrx::Mtrx(dim m, dim n, const bool random_constructed = false, const T min = static_cast<T>(0), const T max = static_cast<T> (10))
Mtrx.C

[Code] ...

And here the relative main section:

Code:
Mtrx rand1 ( 5, 5, bool);// ok
cout<<rand1<<endl;

Mtrx rand2 ( 7, 3, bool, -5, 20);// ok
cout<<rand2<<endl;

Mtrx rand3 ( 7, 7, bool, 0., 15.);// compilation error: undefined reference to
// "Mtrx::Mtrx<double>(unsigned long, unsigned, bool, double, double)"
// collect2: error: ld returned 1 exit status

I compiled in a Linux OS with g++ -std=c++11

View 3 Replies View Related

C++ :: Function To Count Digits Of Entered Number Doesn't Work

Feb 19, 2013

I wrote a program with function my own function which count the digits of entered number. The problem is whatever i type it shows 0 digits.Why is that?

Code:
#include <iostream>
using namespace std;
int cikCipari (int skaitlis, int cipars);
int main()

[Code] .....

View 7 Replies View Related

Visual C++ :: Fill Color In Shapes Using FLTK Doesn't Work For Circles

Aug 28, 2014

I installed FLTK 1.3.X from [URL] on my visual studio 2012 compiler and use PPP book for C++ programming [URL]. My problem is about filling a Shape in.

Code:
#include <Simple_window.h>
using namespace Graph_lib;
int main() {
Simple_window win(Point(100,100), 1000, 600, "Binary_tree");
Graph_lib::Circle c(Point(200,200),50);
c.set_color(Color::red);

[code]....

When I run the program, All three Shapes are drawn on window but only the Rectangle is filled in! Why? set_color works for the three and apparently the set_fill_color is defined for all Shapes and it too should work but why it doesn't for Circle and Ellipse?

This [URL] is the .CPP and .h files ( )

View 6 Replies View Related

C++ ::  How To Make A Loop Until User Asks To Break

Apr 4, 2013

I'm making a program for a MMO I play. It calculates the cash and resources needed to build certain 'modules'. I'm having trouble to do something very simple : make a loop until the user asks to break the loop. Here is what the interface looks like :

What module do you want to install?

(Examples: 'Avenger' or 'VLLT')

dd // I input this
DD. COST each : 60,000 cr.

How many do you want? (Modules left:15)
(NOTE : You may enter a negative number if you made a mistake)
3 // I input this
Current Total Module Price : 180000 cr
+6 droids

[Code] ....

The bigger code box below is a part of the code I made. What I deleted is uninteresting, it's just the same thing again : other resources, other 'modules'...

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
struct resources// Defines the amount of resources and their price

[Code] ....

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved