This code i made divided a user input into characters and non character. The problem im having is that if a mixed sentence is created, such as 32B, it will only print the 'char string' and not the 'non char string'. But when the sentence is just non characters like 32 it will print the 'non-char string'. So essentially if a mixed sentences is created both of the strings won't be created or printed.(This is only a function by the way).
This code i made is a cent converter from 5 to 95 cents. The problem i'm receiving is when the 'cents' function is sent back to the 'main' function it only prints one line. It seems to just print the first if construct that complies with the statement. Is there anyway i can have this function print multiple cent values? For example if 60 cents was entered it would only print '50c', and i want it to print '50c' and '10c' instead.
Code:
#include <stdio.h> int x; void check(int x) { if( x < 5) printf("Less then 5 cannot be calculated "); else if(x > 95)
I am trying to print an outline. My code works up to a depth of 3. (The depth is the number of subsections - so 3 would be section 1, section 1.A, and section 1.A.1). It also works for a width (number of sections and each type of subsection) of 26, where it is capped. However, to get a larger depth, it would involve many more loops. Not only is that terrible code, it also freezes up the terminal I'm working on. I believe recursion would make it much nicer, but I'm struggling to grasp the idea when using a string (I understand when it is a number).
#include <stdio.h> int sec(int width, int snum) { char section[100]; sprintf(section, "Section ");
I need a program that reads the number of lines of a file and then several (max of 20) lines of text from a .txt file so an example of the .txt file is: 2 This is the first string This is string number 2 So it first reads the 2 and then reads the two lines of text. It stores the text in an array of pointers. The code i have so far is:
It doesnt give me any errors but all it does is keep running and doesnt print anything out kind of like its in an infinite loop although i dont see how that could be possible.
I have been skimming and searching but dont know how to word the search just right to find what I need to know. I have written simple stuff with the support of tutorials like weight conversion or loops counting up to a set number. Nothing amazing. The other day I found out how to input and print a string rather than a single text character which i though was bad ass. I even got it to read multiple strings on a single line and found a way to read multiple lines. I can even format it to read both integers and characters on the same line as long as I know the predefined format.
On to my question... How do I read multiple lines with both carecters and integers. for instance:
nissan 1996 toyota 1998 or more comples like nissan gtr 1996 toyota markii 1998
I want to use int year; char make[10]; maybe need to use char make[10][10]; for an array i would guess. char model[10]; optional for the extra data
but reproduce what i read in a different order. say... 1996 nissan 1998 toyota vice the original format.
this is what I have tried.
Code: scanf("%s %s", &make,&year);
//The way I seen to read multiple lines was on here
scanf("%[^/t]", %make);
But this wont let me separate the two into two differnet definded data types. Let alone use printf to display them in reverse order.
if (IS_LEAP_YEAR(year)) const int days_per_month[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; else const int days_per_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; Is it ok to declare the array in this manner or is it bad?
And i have to ask the user for a date to enter in my program. So should I use scanf or should I store the date in a string and then use sscanf. I have to check for valid input for everything like day, month, year etc. I did it as below..
I've a problem with the map construct. I wrote this class in which there are maps:
class Features { private: map<const string,GenericFeatureContainer*> featuremap; map<const string,GenericFeatureContainer*>::iterator it; int size; public: }
This code i made, utilizing the type casting construct, isn't outputting what i wanted. The output for 'Dollars' and 'Cents' are returning '0' for both. instead all i want it to do is seperate the two. for example changing the float value of amount to an integer, giving a dollar value.
How to construct a simple hash function ? When the program executes, it will ask for your name. Type your name and it will print out a "hash code" (a number) from that name.
have a problem with my code (I wish for answer with code). The conditions I have to grant:
- **Only** a pointer to an object must be saved in a **standard** class vector (e.g vector<ShapePtr>) - Base class must be a polymorphic class (I call this class ShapePtr) - I **must** have a deep copy process - Constructor is **not** suppose to do a deep copy - **clone()** is suppose to do the deep copy
Here is the code **provided** to me:
main.cpp int main() { typedef shared_ptr<Shape> ShapePtr; vector<ShapePtr> shapevec;
If I have an integer variable like int a=9 then in the switch case If i write :
switch(a) { case 4+a: printf("hii"); }
Then why is this statement a compile-time error that variables cannot be used inside a case statement why does the compiler not subtitutes the values in place of the variables.
I am trying to construct a program without a main function that outputs stars but at the same time outputs the number and a colon after the number but before the number of star. This is the coding i have so far.
I'm trying to read a "pointer-based" maze .txt. The first letter in each row corresponds to the room letter...then the letters that follow are North node, East node, South node, and West node respectively. The asterisk indicates an empty room or not a valid option.
Here is what I have come up with, what is happening is after the file is parsed by read_maze it is calling my is_empty function indicating that there is no maze because it doesn't go into the else statement here.
I've attached a sample input file:
maze.txt (130bytes) Number of downloads: 19
We can't assume the rooms will be in order alphabetically A - Z, We are expecting a maximum of 12 rooms and there is a space between each letter or asterisk.
void Maze::read_maze(string FileName){
string line; ifstream inStream; inStream.open(FileName.c_str()); int test = inStream.peek(); int i = 0; if (!(inStream.fail())){ while (!inStream.eof() && test != EOF){
I need to construct Truncated Gaussian distribution in the range of (5-20 microns), specifyed by initial standard deviation.
Particularly i need input which comprises of minimum value(5 microns), maximum value(20 microns) and standard deviation of (5,10,20 etc..). In this regard i tried with Box-Muller but it doesn't fulfuil the goal.
I can't get my code to compile, i need to read in lines from a file and store them in variables. Then i have to construct instances of my class for how many lines there are in the file and take those variables into them.
I'm getting this error :
"a2.cpp:40: error: cannot convert `Employee' to `Employee*' in assignment"
#include<iostream> #include<string> #include<fstream> void displayInfo(); using namespace std; class Employee{
I am programming a translator, and I have it so that it detects words with spaces both in front of and behind them, so I did "string.append(space);" where space equals " ". That added a space to the end, but I still need a space added to the front.
I have a problem who must print the sentences who have lenght more than 20 characters. I dont know why, but it prints just the first words. Look what i made.
#include<stdio.h> #include<conio.h> int main()
[Code]....
For instance :
Give the number of sentences : 3
First sentence : I like the website bytes.com Second sentence : I like more the website bytes.com Third sentence : bytes.com
After I compile the program it should print the first two sentences.
What the heck is wrong with my logic? I just print a rectangle!!! I have played with thing for ever it seems. I thought the rotating part would be hard but now I find myself stuck.
I have an array, ary[size+1] and the original values entered and then another value, x, entered. I found the index of x that makes the array nondecreasing order
Code:
void InsertX (int ary[], int size, int x) { int i=0; int j; int index; while(ary[i]<x)
[Code]...
But i can't figure out how to print the new array with x in it, using its index
how to print a box using 2d arrrays. i have to create a tetris game which a im stuck at this stage... so far i have tired i can only come out with this..my coding done so far is as follows:
Code: Enter your desired monthly salary: $2000___ Gee! $2000.00 a month is $24000.00 a year. Instead, it printed out: Code: Enter your desired monthly salary: $2000___
Gee! $2000.00 a month is $24000.00 a year. I don't understand how it got the extra nextline in the middle.
Here is the code:
Code:
#include <stdio.h> int main(void) { float salary; printf("aEnter your desired monthly salary:");