C++ :: Using For Loop To Input And Output Array Values

Jan 23, 2014

so i got this piece of code today having some slight errors with it, how its actually done as i want to know where i have gone wrong here is the code .. Using a for loop to input and output array values

*/
#include <stdio.h>
int main(void) {
/* Declare an array of integers */
int Grades[5];
int nCount;
/* Populate the array */
for(nCount = 0; nCount < 5; nCount++)

[Code]...

View 3 Replies


ADVERTISEMENT

C++ :: Using A For Loop To Input And Output Array Values Also Calculate The Average

Jan 24, 2014

I have this code that im stuck on what i need to do is Extend the code such that when it starts the user is asked to input values to specify each of the three ranges before moving on to accept and tally the main values how do i do that Using a for loop to input and output array values Also calculate the average

*/
#include <stdio.h>
int main(void)
{
/* Declare an array of integers */
int Grades[5];
int nCount;
int nTotal = 0; /* Declare and initialise the value */
float fAverage;

[Code]...

View 1 Replies View Related

C++ :: Passing Values Into Array Using For Loop From Input File

Jul 5, 2014

I'm trying to pass these numbers into the array using the for loop: 1, 2, 3, 4, 5. I created two files in my project called "inStuff.txt" and "OUTPUTS.txt". I know I have an error at my input in the for loop, which is a bit similar to my problem or something? I'm also on linux using a crossGCC complier(not sure if that makes a difference).

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

[Code]....

View 4 Replies View Related

C/C++ :: Input 6 Temperatures In Degrees Fahrenheit And Output In Degrees Celsius - For Loop?

Mar 9, 2015

I need to write a program to input 6 temperatures in degrees Fahrenheit and output it in degrees Celsius. I used a for loop but it keeps giving me 0 as the output whenever I enter a temperature...

Code:

#include <stdio.h>
#include <math.h>
int main() {
double farenheit,celsius;
for(int i=0; i<6; i++) {
printf("Enter temperature in degrees farenheit: ");
scanf("%lf",&farenheit);
celsius = (5/9)*(farenheit-32);
printf("Temperature in degrees celsius: %lf ",celsius);
} }

View 5 Replies View Related

C Sharp :: How To Loop Through Array List For Unique Values

Aug 19, 2012

I am grabbing data from three entities and want to grab a field value in each of the entites and place it in an arraylist. What I would like to do is loop through the arraylist for all the values and do something for each value only once. If the value in the array list is repeated, I want to not do anything for it and continue till the end. Basically, I loop through all the values do something for each value and skip over the repeated value if I already did something.

View 1 Replies View Related

C++ :: Input And Output Array Using Function

Apr 25, 2013

I want to create a function that will accept input from the user and return the input, to be used for further calculation. I know how to accept and return with integers as parameters , but how do i do it with arrays?

Suppose there is an array of numbers arr[]. Now, i want a function that accepts the input from the user, and return the array for further manipulation.

For example, if the array is arr[5], then i should call a function and accept the values from the user. Then, i should return the imputed values and print the same. How can i do this.

View 3 Replies View Related

C++ :: Segmentation Fault In Input / Output Array

Sep 3, 2013

When I try to run the code, I get a segmentation fault core dumped, it returns 139 (0x8B)

The file it is pulling from is a list of numbers, but without the string, the output ends up going from values of ~70,000 to values around 50

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#define MAX 29656
using namespace std;
string el[MAX];
ifstream file1("results.txt");
ofstream file2("Energy1.txt");

[Code] ....

View 1 Replies View Related

C/C++ :: Flip Char Array Input And Output It?

Nov 13, 2014

So my question was:

Write a program to read in a sequence of characters one by one. Print out the characters in reverse. You should use a char[]. (Remember single quotes are used for char)

For example:

Please enter characters one by one: (Enter 0 to exit)
h
e
l
l
o
0
You entered: hello.
The reverse of that is olleh.

and this is currently my code

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <cmath>
using namespace std;
int main() {
char entry[20];

[code]....

im just not sure how to set that value and still make the for loops work

View 1 Replies View Related

C++ ::  how To Input Values Into Array Via Functions

Sep 5, 2014

What "int values" is supposed to mean as parameters to these functions? I'm not sure what do with them. Also how to input values into the array via functions. I was trying to but I just don't understand how to connect a user's input to a function to then enter into an array.

// input reads “values” integers from the user to place in the array data. It prompts the user for each value individually with the ordinal position of the value.
void input (int data [size], int values);
// Places the sum of corresponding values from arrays a and b and places the results in array s. The first “values” integers in the array are processed.
void do_sums (int a [size], int b [size], int s [size], int values);

[Code]...

View 2 Replies View Related

C/C++ :: Matching Input Value To Values In Array

Apr 1, 2015

I have developed the following code for a PIC18 micro-controller. The object of the program is to compare a input value (presumably from a magnetic swipe card), represented here as scan_id, to a list of valid access ID's represented by the array valid_id. If there is a match the program will drive an output pin high to light a green LED for 20 seconds. If there is not a match the program will drive an output pin high to light a red led for 20 seconds.

The issue that I am having is that when the program is executed, the "else" case for the red LED is always selected regardless of the value for scan_id. If I change the "if" statement from == to = then the case for the green LED is always selected regardless of the value for scan_id.

#include <p18f452.h>
#include <stdlib.h>
#include <stdio.h>
#include <delays.h>
void main () {
TRISA=0xFF; /* Configure PORTA<7:0> pins as inputs */
TRISB=0x00; /*Configure PORTD<7:0> pins as outputs */

[Code] ....

View 10 Replies View Related

C :: Can't Input Values In A Dynamically Allocated Array

Oct 5, 2014

this is my function for allocating memory in 2D array

Code:

#include <stdio.h>
#include <stdlib.h>
int allocate_array(int **array, int *row, int *column){
int i;
}

[code]....

end of allocate_array function and this is my function for asking for the values to be stored in array

Code:

int input_array(int **array, int row, int column){
int i, j;
//ask for the values to be stored in the 2D array
for( i = 0; i < row; i++ ){
for( j = 0; j < column; j++ ){
}

[code]....

why I'm having error here in my input_array() function

Code: scanf("%d", &array[i][j]);

View 2 Replies View Related

C++ :: Putting Data Into Array Using For Loop From Input File?

Jul 7, 2014

I'm trying to pass several integers into the array idAr[10] from an input file using a for loop and then having them output on the console. The output should look like this:

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

[Code].....

View 4 Replies View Related

C++ :: Create Simple Input Interface On Console - Allow To Input Values To Variables

Apr 6, 2013

I am trying to create a simple interface on console to allow to input some values to some variables. For ex:

int main() {
double a = 1.5;
double b = 2.5;
double c = 3.5;
string x;

[Code] ....

However, I want these three to display at the same time (now they display one by one), and in the console window I can move the cursor between input place of a, b and c with "arrow key" of keyboard.

View 2 Replies View Related

C/C++ :: Compare Values Stored In First Array To User Inputted Values In Second Array

Oct 19, 2014

Goal: Write a program that compares the values stored in the first array to the user inputted values in the second array.

In order to fix this error: [URL]...

I had to change my array initialization to one with a star in front of it:

char a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};
to:
char *a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};

I also changed my 2nd array to one with a star in front of it: char *a2[20];

What does this mean exactly? Putting a star in front of an array?

Also, I am now getting an "unhandled exception" when I try to get input for my 2nd array:

cin>>a2[i];

View 3 Replies View Related

C :: Possible To Output By Using Only One Loop

Jul 21, 2013

is it possible to output like this using only one loop? if yes, how?

target output Code: ABCDE

EDCBA here is my code but using one loop im not getting my target output Code: #include <stdio.h>

main()
{
int x, y;

for(x='a', y='e'; x<='e'; x++, y--)
{
printf("%c
%c", x, y);
}
getch();
}

View 6 Replies View Related

C++ :: While Loop Stops Output

Jun 19, 2014

As I was testing it, the program suddenly stopped giving an output. Here is the code:

#include <iostream>
using namespace std;

int main() {
cout << "Ten people ate breakfast with you this morning. Each of them " <<
"had pancakes.
Please enter how many pancakes each of the ten people " <<
"ate.
" << endl;

[Code] ...

The while loop after int glutton does not work and seems to stop the program. I replaced the "glutton" in the cout with "testing testing" and it still did not work. However, when I commented out the loop, it appeared. Finally, it can't be what's inside the loop, because I commented that out too, and it still didn't work.

View 2 Replies View Related

C++ :: Struct Output Using A Loop?

Nov 6, 2013

trying to output my struct to a for loop. I understand how to output the struct but not into a for loop.

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
struct Date {
int day;
int month;
int year;

[code]....

View 16 Replies View Related

C++ :: How To Add Values Of For Loop

Feb 9, 2014

I want to add each of the values that are calculated by the end of each for loop.

For example:

for(int i = 0; i < 10; i++)
{
int x;
}

I want to be able to add all of the x values calculated from the for loop together. How to do that?

View 6 Replies View Related

C/C++ :: For Loop Not Producing Correct Output

Nov 14, 2014

Something is wrong with option 1. For some reason it adds 1, 2, 3, 4 ... 5 onto the output and I can't think why. Here is a screenshot.

Also how can I make the output a little neater? I tried to use but it just looks horrible.

I had linked the source code! Why is there no edit button?!

#include<iostream>
using namespace std;
int main(){
int option;
cout << "Welcome to my program. Please select a following option.

[Code] .....

View 3 Replies View Related

C :: Returning Values From While Loop

Jul 13, 2013

I am currently doing a bodyfat calculator for a course in school.I'm having a problem getting an output returned from my while loop, which determines the user's gender by user input.My function (outside of main) is currently:

Code:

char gendercheck(gender){
while (true) {
gender = _getch();
if (gender == 'M' || gender == 'm') {
system("cls");
printf("Your selected gender is male.");
break ;

[code]....

My failed tries include "return gender" and "return genderpicked" statements in both the if-functions and the loop itself, which I have deleted since that didn't work. My goal is to get a character stored in gender, so that I can use the information of the user's gender in my main function from this point and onwards.

MY MAIN IS:

Code:

int main() {
char *genderpicked ;
char gender ;
genderpicked = &gender ;

[code]....

View 9 Replies View Related

C++ :: How To Total The Values That Are Put In During The Loop

Oct 23, 2014

How to total the values that are put in during the loop. For this program I need to add up the values the user inputs and then display them after the loop. Here is what I have:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main() {
const int firstQuiz = 1, lastQuiz = 4;
int quiz, quizGrade;
for (quiz = firstQuiz; quiz <= lastQuiz; quiz++)

[code]...

View 4 Replies View Related

C++ :: Count Function - Nested Loop Output

Feb 28, 2013

What does the following nested loop output ?

count = 1;
while (count <= 11) {
innerCount = 1
while innerCount <= (12 - count) / 2) {
cout << " ";
innerCount++;
} innerCount = 1;
while (innerCount <= count) {
cout << "@";
innerCount++;
} cout << endl;
count++;
}

View 9 Replies View Related

C++ :: Writing Output Of While Loop To Text File?

Jul 30, 2014

[URL] when I try to write my output to a file. I am building a life insurance premium calculator with c++. What my calculator does is read in a text file called "policies.txt" containing a number of different policies. For example:

Pol1 M N 20 100000 1 .04 99
Pol2 F S 30 100000 1 .05 99
Pol3 M S 72 750000 1 .03 99
Pol4 F N 45 1000000 1 .05 99

And using this, it creates a single premium. Once the calculator calculates the premium of each policy, I want it to write out the premium amount of each policy to a textfile called "output.txt". The problem is that when I check my "output.txt" file, only the premium for the last policy shows up. It only reads:

Premium for Pol4 is 220384
When I want it to read:

Premium for Pol1 is 14101.6
Premium for Pol2 is 14221.2
Premium for Pol3 is 582391
Premium for Pol4 is 220384

How come only the last policy is showing up? and is there any way to make all four policies appear in my output text file? Here is my code:

double ratesmn[86] = {
#include "MaleNonSmoker.txt"
- 1
};

[Code]....

View 2 Replies View Related

C++ :: Displaying Correct Output By Using For Loop (with Pointers)

Feb 4, 2014

I wanted to display the correct output by using a for loop at the end of my code, but for some reason it's not working correctly.

#include <iostream>
using namespace std;
int main() {
int* ipArray[3];
for(int i = 0; i < 3; i++) {
ipArray[i] = new int [5];

[Code] .....

What I wanted to do is pretty much match my 1st out put like 0 1 2 3 4 but my 2nd output only outputs 24's and I don't know why

View 11 Replies View Related

C/C++ :: Loop Indentation - Output With No Extra Whitespaces

Mar 1, 2015

So I'm having trouble with my code. Got it to work, but having issues in terms of indenting my increment. For this example, I will use * as whitespaces.

Expected output:
0
*1
**2
***3

Your output:
0
*1
**2
***3
*****

The expected output has no extra whitespaces, but mine does. What am I doing wrong?

#include <iostream>
using namespace std;
int main() {
int userNum = 0;
int i = 0;
int j = 0;
for(i =0; i <= userNum; i++){

[Code] ....

View 5 Replies View Related

C++ :: Enter Name Then Output Name In Vertical Position Using For Loop

Feb 21, 2013

How to fix this when i run the program and enter my name then output my name in vertical position using the for loop and press enter the program do not stop

#include<stdio.h>
#include<conio.h>
#include<dos.h>
main() {
char name,n;
clrscr();
printf("Enter Your Name:");
scanf("%c",&name);

[Code] ....

View 3 Replies View Related







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