C/C++ :: Output Is Not Correct - Squaring Input?

Feb 6, 2015

Ok so This is what the output of the program should be.

enter the count of input integers: 1
The count of the integers must be two or more. Please enter a valid number : 3
Enter integer #1 : 2
Enter integer #2 : -1
Enter integer #3:5

The positive numbers entered and their squares are:

2 4
5 25

My Code :

//header files
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<math.h>

[Code].....

View 6 Replies


ADVERTISEMENT

C++ :: Delete Invalid Input Until Correct Input Is Entered?

Mar 20, 2014

Program is to add two fractions together like so..

This program adds fractions. ‘Y’ continues, any other key exits program
===================================================
Enter numerator 1 ==> 1
Enter denominator 1 ==> 3
Enter numerator 2 ==> 1
Enter denominator 2 ==> 6
1 1 1
--- + --- = ---
3 6 2
-----------------------------------------------------
Continue? Y or N! ==> n

My question is that i need each input to be a number.
if a character is entered i want it to output something like..

This program adds fractions. ‘Y’ continues, any other key exits program
===================================================
Enter numerator 1 ==> 1
Enter denominator 1 ==> a
You need to enter a number here.
Press any key to continue.

and then clear the part where the letter was entered.

This program adds fractions. ‘Y’ continues, any other key exits program
===================================================
Enter numerator 1 ==> 1
Enter denominator 1 ==>

View 5 Replies View Related

C++ :: Output Correct Standard Deviation

Feb 1, 2015

The program does compile the average and the mean correctly. I can't understand why the standard_deviation member function isn't applying the sqrt properly:

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const int N = 10;
class Standard_Deviation {

[Code] ....

View 7 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++ :: Program To Output A Check With Correct Spacing

Oct 14, 2013

So I have to write a program that outputs a check with correct spacing and everything.

Create a project titled Lab7_Check. Write a program that asks the user the check information and prints the check. The dialog should be as follows:

date: 2/23/2010
name: William Schmidt
amount, dollars: 23
cents: 30
payee: Office Max

your check:

William Schmidt 10/13/2013
pay to: Office Max $23.30
twenty three and 30/100 dollars

You may assume that a person always has the first name and last name (no middle names or initials). The payee name is also always two words. The dollar and cent amount are integers and the amount is always less than 100 dollars. Note that the dollar amount could be zero, in which case, when you spell the dollar amount, it should print "zero". The date is always a single (non-white space separated string). Your date, dollar amount in numbers and the word "dollars" have to vertically align.

This is the code I have so far.

#include <iostream>
#include <string>
using namespace std;
int main(){
string date;
string firstname;
string lastname;

[Code] .....

View 3 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++ :: Squaring In For Loops

Feb 9, 2014

I need to make a for loop without: using the math functions like pow, sqrt, etc. or an if-statement.I can only use the basic arithmetic functions like +,-,*, and.The for loop needs to display: 1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192 as the result

How do I make it so my loop works? This is what I have and it doesn't work...and I have no clue how to continue...

k = 0; //k is an int and I have declared it in the beginning of my code
for( k = 0; k < 13; k++ ) {
printf ( "%d, ",k );
k = k * 2;
}
printf("%d", x);

View 1 Replies View Related

C Sharp :: Input String Was Not In Correct Format

Apr 28, 2012

List<Byte> Pt_split(string plain)  {
            List<Byte> pb = new List<Byte>();
            // Byte p;
            string p;
            int temp = 0;
            if (plain.Length % 2 != 0)

[Code] ....

View 2 Replies View Related

C++ :: Fscanf And Verifying Correct Input Length

Jan 24, 2012

I am trying to make a program that will read in input in the following format:

| ...text... || ...more text... || ...still more text...|

i.e. every bit of "text" that gets read in is bracketed on either side by the "|" character.

The buffer that i read them into can be of a maximum length of 101 (100 characters plus a terminating null character); this is how I am currently reading in the input:

char readString [100 + 1];
while ( fscanf(infile, "|%1000[^|]|", readString) ){
/*... manipulate readString ...*/
}

How might I design this program so that, should any of the text appearing between the "|" characters exceed 100 in length, it exits and returns a warning?

View 4 Replies View Related

C :: Unable To Input Correct Form For Matrices Multiplication

Jan 8, 2015

I am unable to input the correct form for matrices multiplication. I have an exam tomorrow in which I need to use this.

Code:

#include <stdio.h>
#include <conio.h>
int main() {
float a[10][10], b[10][10], c[10][10];
int i, j, k, l, n=0, m=0, x=0, y=0, sum=0;
printf("Enter the number of rows and collumns of the first matrix");
scanf("%d %d", &n, &m);

[Code]...

View 7 Replies View Related

C++ :: Correct Answer From File - Cin Getting Wrong User Input

May 31, 2014

So I'm writing a program that will read a text file and it will do certain "functions" the text file will be like a game, and the program will be able to run many different games. The problem i'm having is in one of the "functions" i believe it's the one meant to get a correct choice from a file and a user input and put them into strings, it gets the wrong input. I know this because i tested both strings the "function" writes too. it gets the correct file answer but the user input is always "c" for some reason.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
int progfiles() {

[Code] ....

This is the code, most likely the section that is surrounded with "///" contains the problematic "functions." This is the command Line output...investigate why they're dieing or continue on your journey?(i-investigate/c-continue) got input and answer

i
c
i
Press any key to continue . . .

The got input and answer are tests to make sure it got both, the first 'i' is my input, the 'c' is what it says my input is, and the 'i' is the correct answer from the file. this is the part of the file that the program reads to get that output

"1 Do you want to go investigate why they're dieing or continue on your journey?(i-investigate/c-continue) 2 8 i 7 3 4 You continue on picking up speed to get to the egg first.. and.. Oh No, You accidentally bumped into the walls! 2 12 5 1 You go over, and as you realize the walls are acidic and that's why the other sperm are dieing.. 2 6"

View 3 Replies View Related

Visual C++ :: User Input In Two Arrays - Comparison Always Show Zero Correct Answers

Nov 3, 2012

The following program takes user input into two arrays and should then determine how many items are different by comparing them with a loop. The comparison always show zero correct answers.

#include <iostream>
using namespace std;
const int QUESTION = 20;
//class for testing grades
class TestGrader {

[Code] ....

View 4 Replies View Related

C :: Redirecting Input And Output

Sep 14, 2013

I have this code:

Code:

#include <stdio.h> //printf
#include <stdlib.h> //exit
#include <unistd.h> //fork
#include <sys/types.h> //pid_t
#include <sys/wait.h> //waitpid
}

[code]....

I would like to, when running cat, send in some data like "testing" to its stdin, and then catch the output of stdout, and put it into a character array variable.Currently the parent stalls till the child is done.I imagine the parent has to some how detect that the child executed 'cat', and then send in input to stdin?Then somehow detect that 'cat' is done executing, and read the output from stdout? I have looked around and found "dup2", but I don't understand how to send in and get data to the child from the parent, especially since the "file descriptors" is not pointing to any files in the first place..

View 4 Replies View Related

C++ :: Audio Input / Output?

Feb 5, 2015

So I have a project in which I am processing audio signals in real-time. I want to create a class to do this using the ASIO driver. I don't want to use a cross platform library nor do I want to use windows API as it is very slow.

View 2 Replies View Related

C/C++ :: Console Input / Output?

Sep 7, 2014

I'm trying to write something that when a user is at the command line, the user can type and it displays of list of commands the user can use to run the application.

View 14 Replies View Related

C++ :: Zero And Output The Input With A Setprecision Of 2

Mar 31, 2013

I have a program that needs to output the input with a setprecision of 2 but when it outputs 0, it has to be "0", not "0.00"

How will I go about that?

Here is my code:

void PrintAllSales(double sales[][SLSPRDT]) {
cout << fixed << showpoint << setprecision(2) << endl;
cout << "ALL SALES
";
WriteLine('=', 63);

[Code] .....

And here is how it comes out:

1234
ALL SALES
===============================================================
Product # | 1 | 2 | 3 |
Salesperson 1 | 2000.00 | 0.00 | 299.00 |
Salesperson 2 | 0.00 | 2543.98 | 95.99 |
Salesperson 3 | 0.00 | 0.00 | 19.99 |
Salesperson 4 | 0.00 | 3854.75 | 0.00 |

But it should be like this:

1234
ALL SALES
===============================================================
Product # | 1 | 2 | 3 |
Salesperson 1 | 2000.00 | 0 | 299.00 |
Salesperson 2 | 0 | 2543.98 | 95.99 |
Salesperson 3 | 0 | 0 | 19.99 |
Salesperson 4 | 0 | 3854.75 | 0 |

View 7 Replies View Related

C/C++ :: How To Save New Input Using Output

Sep 11, 2012

I have a project, a montly paycheck. So it checks the monthly paycheck of each employees. but my problem there is how to add a new employee when u are a user or in the output of program?

View 2 Replies View Related

C++ :: String Integer Value - Input / Output

Aug 14, 2013

Code:
Prompt the user to input a string,
and then output the sum of all the digits in the string.

Sample Run 1:
Input -> A111B222C
output -> 9

Sample Run 2:
Input -> ABC123XYZ32100000005555555555zzzzzz
output -> 62

View 1 Replies View Related

C++ :: File Input And Output Structure

Jul 17, 2013

How to structure the input of one .dat file and outputting into another one. I have to loop through a file structured "doe, john, 1500", check for errors and then increase the mp by 50. You also have to do this through using a person class too. I think I need to use a while loop to go to eof and use getline to input correctly, but im not sure how to structure it.

Data file:
Horowitz,Jake,1200.24
Flabitz,Bubba,1712.38
Blackwell,Sharon,1872.93
Molerat,Rufus,501.00
Goodall,Jane,1567.43
Sommerset,William,1359.57

[Code] ......

View 4 Replies View Related

C :: How To Arrange Input / Output Order

Sep 22, 2014

for our school project, we have to make a program which involves three students and the prices each of them paid for the meals. The program has to calculate how much each of the students has to pay/receive to/from the others. Most of it, we got from our teacher. The error we are getting is that we have to 'take care of the input/output order'. So if you type in the names/numbers of the students in a different way, so for example if you type first number 1, then 0, then 2 and 0 and 1 have to pay money to number 2, number 0 has to be in front of 1. Our output is that number 1 is in front of number 0.

insert
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

[Code].....

View 1 Replies View Related

C++ :: Get Input From Ports And Send Output

Jul 30, 2014

I'm learning C++. Is there some way to make program function on input from a port like usb port and can I send bits through the port? For example A usb cable connected to a circuit. I press a button and an AND gate on the circuit gets activated by a bit from the usb port and a fan in the room turns on.

View 1 Replies View Related

C++ :: Assigning Input To Value - Random Output

Jul 24, 2014

I'm using getline, and stringstream to assign an input to a value. How to do something similar with a random output.

//Battle with Samer
#include <iostream>
#include <string>
#include <sstream>
#include <ctime>
#include <cstdlib>
using namespace std;

const char* PokemonSamer[6] = {
"Charizard", "Umbreon", "Mew", "Arcanine", "Espurr", "Luxaray"

[Code] ....

When I run <PokemonSamer[rand() % 6]>, I want to be able to save whatever that output may be, and save it to <string Samer>. Is this possible?

View 6 Replies View Related

C++ :: String Input AND Output To File

Sep 15, 2013

I'm trying to write a simple program that will prompt for a string typed in by keyboard and save it to a file. I've tried lots of variations and this is just the latest version.

//Prompt for a string input by keyboard and save it to a file

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

[Code] .....

View 2 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++ :: Merging Input And Output Files

May 2, 2014

Write a program that opens two text files (input1.txt and input2.txt) for input and one for output (output.txt). The program should merge the two input files in the output files. While doing the merge, it will read one line from input1.txt and one line from input2.txt and write those in the output file one after other. Then it will read the next line from input1.txt and next line from input2.txt and write them one after other in the output file.

This is my code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ofstream myproject;
myproject.open("input1.txt");

[Code] .....

I need to:

1. how to get the second line in the input1.txt file and so on.
2. After the writing in output.txt, count the number of lines in output.txt.
3. write the number of times term ‘line’ appears in output.txt file.

View 3 Replies View Related

C++ :: Console Input And Output At The Same Time

Mar 4, 2014

Alright, so to better myself with network logic I've decided to make a small net game.

I need to input commands to the console as well as output status updates at the same time. I'd prefer to write a gui interface for that, but I'd rather work with WinAPI as little as possible (I mean, look at the way it's designed...).

I'd like to do this with standard operations, limiting dependencies is a must for me.

View 6 Replies View Related







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