C++ :: Count Controlled Loop Than Can Print Char
Sep 27, 2012
Write a count controlled loop than can print "i" char. The user is supposed to input a integer and that integer is how many asterisks there is on the blade, in this case it is 5.
* *
** ** **---------------
*******
** ** **
* ** * -10 Rows high
** -blade always connects on second row of handle
**
**
**
**------------------
These are the steps he told us to do it in.
1) *
**
***
****
*****
2) *
**
***
****
*****
****
***
**
*
3) * *
** **
*** ***
**** ****
**********
4) * *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *
5)* *
** ** **
*******
** ** **
* ** *
**
**
**
**
**
View 4 Replies
ADVERTISEMENT
Jan 2, 2014
The program should be print the numbers 0 through 10, along with their values doubled and tripled. The data file contains the necessary variable declarations and output statements.
Example the output:
Single Double Triple
1 2 3
2 4 6
3 6 9
4 8 12
here my code tell me if correct
#include <iostream>
#include <cstdlib>
using namespace std;
int main () {
int x, double, triple;
[Code] .....
View 1 Replies
View Related
Dec 16, 2014
4.1 Write a program that will count from 1 to 12 and print the count, and its square, for each count.
4.2 Write a program that counts from 1 to 12 and prints the count and its inversion to 5 decimal places for each count. This will require a floating point number.
4.3 Write a program that will count from 1 to 100 and print only those values between 32 and 39, one to a line. Use the incrementing operator for this program.
View 2 Replies
View Related
Feb 12, 2014
I have the following code to print a string to the LCD using my PIC32 Starter Kit; I have made this code work with success. I cannot, however, make the LCD print numbers.
#include<p32xxxx.h>
#define LCD_PRT PORTE //LCD DATA PORT
//#define LCD_DDR DDRE//LCD DDR
//#define LCD_PIN PINE//LCD PIN
[Code].....
I want to change the original code as little as possible, don't worry about my header files - they are fine.
View 2 Replies
View Related
Apr 15, 2014
I am trying to keep a count on a variable name stored within a structure as char*'s. They are of the same field and I do not know how many there will be so I would like to keep a standard name and append the count.
So say I have a variable name such as "desk", but as I have many of these said desks so I would like to call them "desk1", "desk2", "desk3" and so forth. Any recommendations on how I could do this?
Also since this is somewhat relevant is there an easy way to convert from an integer to a string, something that would work like atoi() in reverse? I wouldn't mind writing a method to do so myself but haven't a clue as to how.
View 5 Replies
View Related
Apr 16, 2013
I am using a for loop to count down from 10 to 0 it's working to count down from 10 to 1 but when the program cames to the 0 then the program freezes by any reason.
Code:
#include <iostream>
using namespace std;
int main()
{
int number[2];
cout << "Enter number: ";
cin >> number[0];
if (number[0] == 1)
[Code] ....
View 11 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
Mar 14, 2013
I have to write a c++ program to read html code and do bunch of stuff. One thing that i have to do is to count the no of attributes and sort them in descenting out and print out only first 10 frequently used attributes. I counted them using maps and sorted them using multimaps but now dnt knw how to print only 10 elements
for(std::map<string, int>::iterator it = Element.begin(); it != Element.end(); ++it)
Elements.insert(pair<int, string>(it->second, it->first));
for(std::multimap<int, string>::reverse_iterator it = Elements.rbegin(); it != Elements.rend(); ++it) {
cout << "Element: " << it->second << " : " << it->first << endl;
}
This is how i did it . How to display only 10 elements and not all the elements.
View 17 Replies
View Related
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
Aug 3, 2014
So I have been given and as part of the solution I need to count the number of digits in a long long variable. To do this I use a while loop, but it is behaving strangely. Here is the code.
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main (void) {
printf("What is the card number?");
long long card = GetLongLong();
if(card <= 0)
[Code] .....
When I execute the program it asked for the number, but then nothing happens. Of course, my first instinct was that the program was caught in an infinite loop somehow, but could not figure out how. I commented out the while loop and the program completed (albeit returning the incorrect value), so I was further convinced that there was an infinite loop that I was not seeing. I ran the program throug gdb. Strangely, the program did not loop infinitely, instead it got to line 16 [while(card1 > 0] and then just stopped, it was not executing the next line of code at all.
View 6 Replies
View Related
Apr 23, 2013
How do I print an unsigned char in c++? E.g.
unsigned char a[100] = "acdef";
wprintf(L"a is %u
", a);
wcout << "a is " << a << endl;
gives
a is 2880488
a is 002BF3E8
and not
a is acdef
a is acdef
??
what is the difference between unsigned char and char?
View 6 Replies
View Related
Nov 25, 2014
In this project I need to develop few functions to work with graphics card. I work in minix and this is pretty rubbish.
I'm having an hard time to read a pixel map, or atleast ro print it on my main function.
I have a read_xpm function, which is given, therefore, working.
char *read_xpm(char *map[], int *wd, int *ht)
then I have a pixmap.h file which gives some examples of pixmap images that I can use as example:
static char *pic1[] = {
"32 13 4",
". 0",
"x 2",
"o 14",
[Code]....
I tried something like read_xpm(xi, yi, *xpm[0]); but I'm guessing I need to index that array and run all those chars in order to show them.
View 3 Replies
View Related
Apr 9, 2014
write a c++ program that reads an unknown number of integer values and then print count, sum and average of odd values, even values, positive values, negative values!!
View 1 Replies
View Related
Mar 21, 2013
I'm working on a personal project with a screen that looks like this:
+++++
+++++
++O++
+++++
+++++
And below that it asks where you want to move. I've done the majority of the work, I just have to figure out how to actually move the O. Here's my source code:
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
[Code]....
View 2 Replies
View Related
Jun 3, 2013
need to create a program for the following problem
1.Program takes messages as input at a rate “X” msg/sec, and outputs those messages at “Y” mgs/sec in a file.
2.The peak value of X can be 10msg/sec, and Y can be at max 5msg/sec. System should be designed in such a way that it can handle the peak input rate of 10msg/sec for not beyond 5 minutes.
3.Message contains following fields – unit id, timestamp, temperature.
4.Input data to be read from a file. Output data to be written to a file.
5.For testing design 3 types of profiles –
a.Profile 1 for 10 min – low rate, i.e. X = 4 msg/sec on an average throughout the period.
b.Profile 2 for 10 min – Max rate, i.e. X = 10 msg/sec for 2 min; then a sleep of 2 min, then repeat the same pattern till complete period
c.Profile 3 for 10 min - Max rate, i.e. X = 10 msg/sec for 5 min; then no traffic for next 5 min
View 1 Replies
View Related
Mar 30, 2013
I have most of the code working properly, but I'm having trouble with a certain area. Currently I have multiple 2D arrays. One is a char array and the other is an int array. In the int array I have to find the max number in each column, which I've done. The problem is, I need to print the max number's row in relation to the char array's row.
For example,
Code: int array[2][3] = {60 50 30 0 100 1}
The max numbers are 60, 100, 30.
char array[2][length+1] = {nameOne nameTwo}
How it needs to print:
nameOne has max score of 60.
nameTwo has max score of 100.
nameOne has max score of 30.
I just can't understand how to compare the two arrays in the right way, so it'll know that nameOne is associated with the numbers in row 0 and nameTwo in row 1, etc.
View 1 Replies
View Related
Aug 26, 2013
I was assigned to print a linked list but as a vector of char (I cannot use the normal string type) , this is what I have:
char* List::asString(){
Node* ite = new Node();
ite= first;//ite is like an iterator of the list
for(int i=0; i<sizeOfList; ++i){//sizeOfList is the total of node of the list
[Code] ....
But when I print that, I get a bunch of weird symbols...
View 7 Replies
View Related
Nov 10, 2014
#include <fstream>
#include <ostream>
#include <iostream>
#include <iomanip>
using namespace std;
const int NAMESIZE = 15;
const int MAXRECORDS = 50;
[Code] ....
View 2 Replies
View Related
Dec 20, 2013
I have written below program to count number of words and lines and print the all the words.
#include <iostream>
using namespace std;
#include<fstream>
#include<string.h>
int main() {
ofstream outfile;
[Code] .....
Its compiling fine but when executed its displaying I infinite times...
View 3 Replies
View Related
Mar 6, 2015
I am making a program that takes the user's family names, their ages, and where they live. At the end I will be eventually averaging out their age and also printing the names of anyone who lives in Kansas.
I can't seem to get the Kansas part to work properly though.. When I execute the code, everything else works perfectly, but the Kansas part doesn't even print. Is there something different I need to do when strings are involved rather than integers/floats?
Code:
#include <stdio.h>
int main ()
{
/* variable definition: */
[Code].....
View 6 Replies
View Related
Mar 24, 2015
I am making a program that takes the user's family names, their ages, and where they live. At the end I will be eventually averaging out their age and also printing the names of anyone who lives in Kansas.
I can't seem to get the Kansas part to work properly though.. When I execute the code, everything else works perfectly, but the Kansas part doesn't even print. Is there something different I need to do when strings are involved rather than integers/floats?
#include <stdio.h>
int main () {
/* variable definition: */
[Code].....
View 3 Replies
View Related
Jul 1, 2012
I would like the following code to print: "Why doesn't this print?" and "I would like to print the sum of nc: 5". What am I doing wrong.
#include <stdio.h>
//Use to test ideas and formats//
main() {
int c, nc;
nc = 0;
[code]....
My result as compiled by gcc -o testing testing.c
This prints.
test
t1,e2,s3,t4,
5,
I have not figured out how to sum and print as the above code indicates, which complicates my ability to do many of the exercises in "The C Programming Language". I am using a MacBook gcc compiler and X code as well. I cannot get the last two printf functions to work. I did the temperature example with "while (fahr <= upper)" and the printf printed.
View 7 Replies
View Related
Mar 24, 2013
Is it possible to create a program like Robocode, a game controlled at runtime by an external source file in visual c ++? For example create a checkers game where there would be an external source file, read at runtime, which would play automatically, with artificial intelligence. You can? If yes, how?
View 9 Replies
View Related
May 31, 2013
I'm working on a project that uses type char instead of type int to make selections in a menu that calls functions. I'm really hitting a wall with the while loop, I'm pretty sure my syntax is wrong for type char.
#include <iostream>
#include <cmath>
using namespace std;
// ***********************************************************************
void ShowMenu();
void SquareRoot(double UserEntry);
[Code] .....
View 1 Replies
View Related
Sep 29, 2014
I'm attempting to print a series of text from this loop, but for some reason all I am getting is the sum total and the number 1, like this
1 5175.11
When I want to get it for each iteration of the loop. I've cycled over this and compared it to my other loops I've used and I'm lost as to why this isn't working. I also tried using a do while but that didn't work as well.
for (double total1 = 0; total1 < goal; total1 + save_amt) {
total2 = ((factor - one) * save_amt);
total3 = (total2 / fr_interest);
total1 = total1 + total3;
months_dis = (months_dis + one);
cout << months_dis << " " << total1 << endl;
}
View 14 Replies
View Related
Aug 25, 2013
I am creating a pizza program for ordering a pizza and I have removed all the errors except for two. I have tried everything I can think of to fix this problem so it will compile, but to no avail. The only errors left are:
1>------ Rebuild All started: Project: Pizza Order App Midterm, Configuration: Debug Win32 ------
1> stdafx.cpp
1> Pizza Order Midterm.cpp
1> Pizza Order App Midterm.cpp
1>c:usersindia-n-jerrydocumentsvisual studio 2010projectspizza order app midtermpizza order app midtermpizza order app midterm.cpp(57): warning C4390: ';' : empty controlled statement found; is this the intent?
[Code] ....
The entire code is listed below seperated into 1 header and 2 cpp files.
// OrderPizzaApp.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
#include "Pizza_Order.h"
#include <iostream>
#include <string>
using namespace std;
// prototypes
Pizza_Order createPizza_Order();
[Code] .....
View 5 Replies
View Related