C++ :: Program That Prints A Discounted Product

Sep 29, 2014

So I need to make a program that reads distance and number of days of a person that is buying a ticket. If distance is greater than 1,000 kilometers AND the person stays more than 7 days, the discount is 30% of the ticket. The cost per kilometer is $1300. Print the ticket with discount.

I used variable distance as float because it will be multiplied with 0.3 for the discount... not sure if I'm right on that.

Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
float distance;
int days;

[Code] .....

I tried another way but haven't done it in code...

ask for distance
ask for days

Ticket= (Dist x 2 x $1300)
If (dist>1000) && (days>7)

cout<<Ticket=Ticket * 0.3;
else { cout<<Ticket;

View 2 Replies


ADVERTISEMENT

C++ :: Change Making Program Prints Correct Values But Prints Them In Loop

Jan 27, 2015

I have a program that makes change from an amount. It works fine, but the output is the correct output looped over and over. I have tried everything, but it still doesn't work. For example, a amount of 98 should print

3 quarters
2 dimes
0 nickles
3 pennies
but instead it prints
3 quarters
2 dimes
0 nickels
3 pennies
0 quarters
2 dimes
0 nickels
3 pennies
0 quarters
2 dimes
0 nickels
3 pennies

Why it's doing this?

Code:
#include <iostream>
using namespace std;
int coinscount(int& amount, int value) {
int tracker = 0;
int amountdimes = amount;

[Code].....

View 3 Replies View Related

C++ :: Program Prints Correct Result But Prints It Over And Over

Feb 9, 2015

I have a program where the user inputs a line of integers, and then all unique ones are outputted. It works fine-almost. It prints the numbers correctly, but prints them more than once and I'm not sure why.

Code: #include <iostream>
using namespace std;
int main ( ) {

[Code]......

View 10 Replies View Related

C :: Calculate Product Of Two Matrices - Segmentation Fault In Program

Oct 29, 2014

New to C Programming, I have a problem with a little program I made that calculates the product of two matrices.

And here is the error I get:

View 4 Replies View Related

C :: PPM Program That Prints Certain Pictures

Oct 8, 2014

I need to make a program that prints certain pictures. My program compiles successfully. However, I cannot figure out how to view the ppm output. When i run the program i get a lot of random text.

View 2 Replies View Related

C++ :: Program That Prints A Triangle Of Symbols

Jan 1, 2015

I'm making a program that prints a triangle of @ signs given rows (but not columns).

For example, the output with rows = 4 would be:
@@@@
@@@
@@
@

and rows = 3 would be:
@@@
@@
@

However, trying to make this has given me a program that does something similar (but not the same):

for example, with my current program rows = 4 outputs:
@@@@
@@@
@@
@

and rows = 3 gives
@@@
@@
@

It seems that it's just missing a space (and therefore a setw and setfill), but I found 2 problems:

1. The space needs to not apply to the first line.
2. I can't get it to make a space before each row without making a space between each column.

My current code is:

#include <iostream>
#include <iomanip>
using namespace std;
int main ( ) {
int rows;

[Code] ....

I have tried putting in << setws and << setfills of various values but it seems to always apply to between each column as well as at the start of each row- what do I do?

View 4 Replies View Related

C++ :: Program That Prints Out Pascal Triangle?

Jan 20, 2015

I have a program that prints out pascal's triangle. One problem: it isn't a triangle. The output doesn't work. This is what it should print:

Code: How many rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1 and this is what it does print: Code: Enter a number of rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

[Code]....

View 3 Replies View Related

C++ :: Program That Prints Out Random Numbers

Nov 1, 2013

output should look like this -

So far i have this

[code]#include <iostream>
#include <time.h>
using namespace std;

int main() {
srand(time(NULL));

[Code] .....

I am getting these errors when i compile it

random.cpp: In function âint main()â:
random.cpp:23: error: expected â,â or â;â before numeric constant
random.cpp:24: error: âRâ was not declared in this scope
random.cpp:25: error: âRâ was not declared in this scope
random.cpp:26: error: âRâ was not declared in this scope
random.cpp:27: error: âRâ was not declared in this scope
random.cpp:28: error: âRâ was not declared in this scope

View 3 Replies View Related

C++ ::  Write A Program That Prints Out The Even Integers Between 2 And 100

Nov 4, 2013

#include <iostream>
using namespace std;
int main()
{
int num = 2;
int count = 0;
while (num <= 100)

[Code]...

The code works fine but I need the results to print out like

2 4 6 8 10 12 14 16 18 20
22 24 26 28 30 32 34 36 38 40

instead of

2
4
6
8
10
12

I don't know how to do this.

View 7 Replies View Related

C++ :: Program That Prints A Triangle Of Symbols In A Certain Direction

Jan 12, 2015

So I need to make a program that prints a triangle of symbols in a certain direction.

For example: Code: How many rows? 3

@
@@@
@@@@@

How to do that. It's rare that I post without figuring anything out, but I'm just simply not sure. I have a program that prints a triangle in a similar direction, so maybe if I could get some hints as to what to do with that (HINTS, not direct source code) .

Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main ( ) {

[Code] .....

View 6 Replies View Related

C++ :: Program That Prints Prime Factors Needs To Have Them Output In A Specific Way

Jan 6, 2015

I am working on an assignment to enter a number and print all the prime factors of that number. I have that working, but the assignment demands the output be formatted in a strange way which I can't figure out. For example, in my current program entering 10 gets me 25, which is actually 2 and 5. But it should get me: ( 2 * 5 ) but I can't figure out how to do this. On the chance you need it, my code is below:

Code:

#include <iostream>
using namespace std;
int main( )
{
cout << "Number: ";

[Code].....

View 12 Replies View Related

C :: Program That Prints Multiplication Table Using Nested Loops

Mar 9, 2013

Write a program that prints a multiplication table using nested loops. In main ask the user for the smallest column number , the largest column number and the size of the increment. Ask the user for the same information for the row values.

In the example the column values entered are: 5, 15 and 2 and the row values 3, 6 and 1.

Given those numbers you would generate the following table.

Multiplication Table
| 5 7 9 11 13 15 ___|___________________________________ | 3 |
15 21 27 33 39 45 4 | 20 28 36 44 52 60 5 | 25 35 45 55 65 75 6 | 30 42 54 66 78 90
Print the 24 values with the grey background. The other numbers show the values to be multiplied.

Code:
#include<stdio.h>
main() {
int a,b,c,d,e,f;
int i,j,total;
printf("Please enter smallest column number: ");
scanf("%i",&a);
printf("

[Code] ....

Challenge:
As an added challenge try to print out the column
headings (5 7 9 11 13 15) and the row headings (3 4 5 6)

View 1 Replies View Related

C :: Create A Program That Prints A Number Of Dots Specified By User

Oct 8, 2013

I'm trying to create a program that prints a number of dots specified by the user, there 4 options to do any loop type or to exit the menu. i'm having problems making it so that after you enter a value and it displays the specified number of dots it clears the results. Also we have to make it so that if a negative integer is entered it still prints out the appropriate amount of dots ie: user puts -9 it prints 9 dots, i know you use the abs() function but it doesn't seem to be working for me. I'm assuming my problem with the abs function is i'm not using it correctly. Use case 1 as the example for the rest because I'm trying to implement everything on one case at a time

Code:

int main() {
//initialization statements
int Num1 = 0;
char dot = '.';

[code]....

View 7 Replies View Related

C++ :: Program That Prints Out Memory Addresses Of Each Element In Two Dimensional Array

Jun 21, 2013

the question is; Write a program that prints out the memory addresses of each element in a two-dimensional array. Check to see if the values printed out make sense to you based on the way I explained it before.

Below is the code I have done. I am having problems printing the "-" sign to keep formatting with the board when the user enter in different dimensions other than [4][4].

Code:

#include <iostream>
using namespace std;
void printTable (int x, int y) {
int **p_p_twoDimension = new int* [y];
for (int i = 0; i < y; i++) {
p_p_twoDimension[i] = new int [x];}

[Code]...

View 12 Replies View Related

C :: Gender Program That Interpret M And F Inputs And Prints Guy / Girl Message

Apr 10, 2014

How do I write a program that'll interpret "M" and "F" inputs and print a "you're a guy" or "you're a gurl" message?

Code:
#include <stdio.h>
#include <conio.h>
char gender;
char main(void) {
printf("type M or F

[Code] ....

View 5 Replies View Related

C/C++ :: Program To Print Product Of Even Numbers And Sum Of Odd Numbers Between 1 And 30

May 20, 2014

I want to make a program to print the product of even numbers between 1 and 30 and sum of odd numbers between 1 and 30. But the answer of product is negative. The photo shows the output of the code.

#include <stdio.h>
#include <conio.h>
void main ()
{
int i, even_product=1, odd_sum=0;
for(i=1;i<=30;i++) // For loop starts here!

[Code]...

View 5 Replies View Related

C/C++ :: Unable To Create A Program That Takes Command Line Arguments And Prints Last One

Jan 18, 2015

I'm just getting back into the swing of things after a long time of not programming. I'm trying to create a program which takes in command line arguments and prints the last one. My code is as follows:

#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
string x;
vector<string> arguments;

[Code]...

And the error message I receive, a simple but frustrating one, is as follows:

Enter arguments, enter STOP to stop: Segmentation fault...

View 1 Replies View Related

C/C++ :: Create A Program That Prints A Certain Number Of Asterisks Based On User Input

Apr 12, 2015

I need to create a program that prints a certain number of asterisks based on user input. The user inputs 5 and I want my program to output "*****". How would I do this in C? I've tried printf("%#**", myvariable) but this does not work it only prints "*".

View 1 Replies View Related

C :: Program Where User Inputs A String And Prints Out Length Of String

Jan 29, 2014

I would like to understand a function on strings. Below is a code that I took from my teacher where the user inputs a string and prints out the length of the string.

Code:
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int i = 0;

[Code] ....

Now I understand that it returns the count in "int" so my question is:

Let's say i declared

Code: int count = 0;
at the beginning of the code and then made
Code: count = strlen(str);
why wouldn't i have the same result? Is there a way to do it also?

View 7 Replies View Related

C++ :: Make Program That Prints Out 10 Random Questions From 15 Questions?

Oct 29, 2013

I need to make a program that prints out 10 random questions from the 15 questions in a .txt file, and then print out the choice IN RANDOM.

View 7 Replies View Related

C++ :: How To Get The Cross Product

Oct 10, 2014

I am trying to compute the cross product of an 1x6 column vector "D" with a 6xN matrix "S".

vector< vector<float> > D(1, vector<float>(6));
vector< vector<float> > S(6, vector<float>(10)); // Example where N = 10
float cProduct = D*S; // ?

The last line fails, so I'm wondering how you would get the cross product?

View 2 Replies View Related

C++ :: For Loop To Sum Up Product Of Several Arrays

Feb 2, 2013

I need a for loop that sums up the product of several arrays.

int total = 0;
for (int i=0; index < (columns - 2); index++)
for(int indexFF = 0; indexFF < CG[index + 2] - 1; index++)
for (int indexIN = 0; indexIN < CG[index + 1] - 1; indexIN++, total++)
NRN[CG[index + 1]+indexFF] += FF[total] * NRN[indexIN + CG[index]];

right now "columns" is set to 3

CG[] is an array of 10 integers for "column groups"

for now they are set to:

CG[0] = 0
CG[1] = 3
CG[2] = 4
CG[3] = 3

NRN[] is an array of floating points
NRN uses CG to map its indexes out

0 3 7
1 4 8
2 5 9
_6

FF[] is an array of random numbers basically constants

I need the for loops to sum:

NRN[0] = 0.5
NRN[1] = 0.75
NRN[2] = -1
NRN[3] = NRN[0]*FF[0] + NRN[1]*FF[1] + NRN[2]*FF[2]
NRN[4] = NRN[0]*FF[3] + NRN[1]*FF[4] + NRN[2]*FF[5]
NRN[5] = NRN[0]*FF[6] + NRN[1]*FF[7] + NRN[2]*FF[8]
NRN[6] = -1
NRN[7] = NRN[3]*FF[9] + NRN[4]*FF[10] + NRN[5]*FF[11] + NRN[6]*FF[12]
NRN[8] = NRN[3]*FF[13] + NRN[4]*FF[14] + NRN[5]*FF[16] + NRN[6]*FF[17]
NRN[9] = -1

NRN, FF and CG are the only things in other code that I can't change in the loops

when I debug it index goes to 3 and overflows its memory. which it shouldn't because columns = 3 so "index < (columns - 2)" should stop at 1

View 2 Replies View Related

C :: Creating Product Inventory File?

Jan 26, 2013

How to make a program in C to create a product inventory file containing pro0duct name, cost and quantity and then read the prouct inventory file.

View 9 Replies View Related

C++ :: Kronecker (direct) Vector Product

Feb 19, 2013

How to code the Kronecker/direct product of two vectors??

The direct product of the vectors a and b is given as the matrix below (note "x" refers to x with a circle around it and is the symbol for a Kronecker product):

(a1, a2,..., an) "x" (b1, b2,...,bn) = [a1b1, a1b2,..., a1bn]
[a2b1, a2b2,..., a2bn]
[ . . . . ]
[ . . . . ]
[ . . . . ]
[anb1, anb2,..., anbn]

The way I have coded the rest of the program is such that the matrix shown here is represented by a vector of length equivalent to the number of elements in the matrix. So I want the Kronecker product to give me a vector of length n^2 (where n is the number of elements in each initial vector).

View 3 Replies View Related

C++ :: Compute Area Of A Triangle Using Cross Product

Jan 8, 2015

I have to write some cpp program which computes area of a triangle using cross product,we give 3 vertices as R2 and 3 edges as double.

I am beginning like this;

#include <iostream>
#include "R2.h"
#include <cmath>
using namespace std;
double area ( R2 *A,double *z)

[Code] .....

View 5 Replies View Related

C++ :: Calculate Product Of 4 Vertical Values In Matrix

Jun 1, 2013

I am attempting to create a program which calculates the product of 4 vertical values in the matrix. The numbers are supposed to be randomly generated and the size of the matrix is given through the command window.

However I seem to have either not pointed my matrix through all of my functions correctly, or my logic is off somewhere as I keep getting this output regardless of the size of matrix I put in:

"the location of the highest horizontal line product is: 5 0 and is the number: 0

The overall max value is 4196352 at the above coordinates."

using namespace::std;
//srand(time(0));
int h_line(int**, int, int);
int v_line(int, int,int);
int diagnol_left(int,int,int);

[Code] .....

View 2 Replies View Related







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