C++ :: C Type Strings - Program To Ask User To Enter A String And Perform Functions

Oct 18, 2014

My assignment is : Please use C type strings ( array representation of strings). Write a program that will ask the user to enter a string. It will then regard that string as a worked-on string and allow the user to perform the following editing functions on it:

s – search
i – insert
a – append
d – delete
a – append
d – delete
r – replace
e – exit
s – search

This option will allow the user to search for a specified string in the worked-on string. If the string is

found, it will display the starting index (position) of the searched string in the worked-on string.

here is what i have so far.

#include <iostream>
#include <cstring>
using namespace std;
int main() {
char a_string[80];

[Code] .....

View 4 Replies


ADVERTISEMENT

C++ :: Enter As Many Numbers Until User Doesn't Type E To Exit

Oct 27, 2013

Enter as many numbers as you want as long as the user doesn't type 'e' to exit.

Problem: When I enter a number, it works fine, but if I enter e then it'll go in an infinite loop since the letter is being stored in an int variable. How can I (when I press 'e') make it convert to a char to make it end the program?

#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number or press e to exit:";

[Code] ....

Our class has just started c++ and we have not learned arrays and classes yet, so I'm guessing there is a way to do this without it? Or no?

View 2 Replies View Related

C++ :: Output Vowel From User Input - Error With Strings And Functions

Nov 25, 2014

The program is supposed to read in a string from the user and then output the number of each vowel that the string has. My first function is initializing the vectors, and the one that I'm having trouble with is the function used to read the string from the user and save it.

Here's my code:

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;

// FUNCTION PROTOTYPES GO HERE:
void init_vectors(vector<char> & vowels, vector<int> & frequencies);
string read_text(const string & prompt);

[Code] ....

And I'm getting the error:

freq.cpp: In function ‘std::string read_text(const std::string&)’:
freq.cpp:74: error: no matching function for call to ‘getline(std::istream&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’

I'm not too sure if I can't use the function getline here or if there is something wrong with the function prototype itself but I'm pretty sure there isn't an error there as it was given to me.

View 4 Replies View Related

C++ :: User Defined Functions - Type Name Is Not Allowed

Dec 5, 2014

So I received an error of "type name is not allowed" and I don't know how to fix this.... Here is the code:

retrieveData(string Name, double wage, double hours, int exemptions, char Status);
dataCalculations(double wage, double hours, int exemptions, char Status, double grossPay, double ficaTax, double incomeTax, double netPay, double taxWithheld);
sendData(string Name, int ID, double hours, double wage, double ficaTax, double incomeTax, double grossPay, double netPay);

View 9 Replies View Related

Visual C++ :: Allow User To Enter A Value As C String In Certain Form

Oct 14, 2013

My program was to allow the user to enter a value as a C string in the form: xxx,xxx,xxx,xxx,xxx.xx, where x can be any digit. Well, so far here is my attempt. I think the question is, would I have to implement a switch statement for the digits, the comma, and the decimal, so that when a user inputs, let say 52,000.00 the switch statements would read the 1st digit, checks for decimals/commas and if not, proceed to read 2nd digit, and repeat?

Code:
#include <iostream>
#include <string>
int main() {
using namespace std;
char buffer[256];
char tempBuff[256] = {'

[Code] ....

View 3 Replies View Related

C++ :: Allow User To Enter A String And Output In All Uppercase Letters

Oct 24, 2014

/* Program is to let the user enter a string and will output the sting in all uppercase letters. */

#include <cctype>
#include <iostream>
#include <string>

using namespace std;
char str1[80];

[Code] ....

I am trying to get the cin.get working where the user is allowed to enter an 80 character string and how to do that.

View 1 Replies View Related

C :: Program That Will Allow A User To Enter Their Name

Jul 2, 2013

I am trying to make a program that will allow a user to enter their name, from this point, three options should be present for the user to choose, then from that point, two more options should be present. I have if else statements in a switch case and I get the "undeclared" error for the a in the first " if(specificage == a) ".

NOTE: I use Code::Blocks.

Here is the code:

Code:
#include <stdio.h>
#include <string.h>
int main(){
char name[50];
char ageclass[50];
char specificage[50];

[Code] ....

View 3 Replies View Related

C++ :: Program That Will Ask User To Enter Area Of Square?

Feb 11, 2013

B. Circle in a Square Write a C++ program that will ask the user to enter the area of a square. Then the program will display the biggest area of a circle that will fit in a given square. Using math.h library is not allowed.

View 1 Replies View Related

C++ :: Program That Asks User To Enter Even Number Only

Mar 23, 2014

Write a C++ program that asks the user to enter an even number only. If the user enters an odd number the program should use input validation to ask the user to enter another number.

- The user can enter as many numbers as he wants

- The program should also keep a count of how many numbers entered and display how many odd and even numbers entered.

View 1 Replies View Related

C :: How To Terminate A Loop If User Inputs Blank Space In A String Or Press Enter

Jan 28, 2015

Code:

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
int main(void) {
int i;
char *str;
int len = 1;

[Code]...

View 3 Replies View Related

C++ :: Program Which Allows A User To Enter Input For A Time Interval

Apr 23, 2014

how can i make a program which allows a user to enter an input for a time interval for example i ask a question and sets the input to be entered within 10 seconds...

View 4 Replies View Related

C++ :: Program That Allows User To Enter Statement And Outputs Statistics?

Dec 12, 2013

a program that allows the user to enter a statement and outputs statistics; number of vowels, number of constants, percentage of vowels and constants, number of words, number of punctuation characters

View 2 Replies View Related

C++ :: Write A Program That Prompts The User To Enter Integer?

Nov 8, 2013

Write a program that prompts the user to enter an integer and then displays that integer as a product of its primes and if it is a prime then it should say so? Above is the question I have been given

#include <iostream>
#include <vector>
using namespace std;
int main () {
int num, result;
cout << "Enter A Number " << endl;
system ("pause");
return 0;
}

This is what I have so far, do I have to use a for loop, a while loop or a do loop,

View 7 Replies View Related

C++ :: Write Program That Asks User To Enter Student Grades?

Jan 21, 2014

Write a program that asks the user to enter a student’s grades on four exams. The program should display the four grades and the average of the four grades,rounded to the nearest tenth. To add the grades, use a variable called total_grade, which you should initialize to zero.As the program prompts for and obtains each grade, add the grade to total_grade using the += operator.

View 3 Replies View Related

C++ :: Write Program That Prompts User To Enter Item Number

Jun 27, 2013

Write a program that prompts the user to enter an item#, the program should determine if the item is in the file and print the price of the corresponding item. If the item is not in the file an error message should be printed.

All I have so far is

string item_no=0;
cout<<"Enter a item#";
getline(cin,item_no);
if stream openData;

I need to finish the rest in pseudo code

View 2 Replies View Related

C :: Generate A Program That Will Allow User To Enter Data For A Stock And Calculate Amount Of Stocks

Oct 5, 2013

Okay, so my assignment for my C class is to generate a program that will allow the user to enter data for a stock and calculate the amount of stocks that ended up being positive, negative, and neutral.I tried to do this using one stock, here is my code;

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

Code:

void main()
{
float Neg;
float incst;
float shrs;
float bpps;
float crnt;
float crntcst;
float yrfes;
float pft;
float tpft;
}

[code]....

View 6 Replies View Related

C/C++ :: Creating Program That Allows User To Enter Unknown Number Of Income / Expense Amounts

Feb 21, 2014

I'm trying to create a program that allows the user to enter an unknown number of income and expense amounts. The program has to us see a while loop and display the income total, expense total, and total profit or loss. I've got it really close, but I'm doing the loop wrong. It counts the sentinel value (-1) towards the total, instead of just ending like it is supposed to.

#include <iostream>
using namespace std;
int main() {
//declare variables
double incomeInput;
double expenseInput;
double incomeTotal=0;
double expenseTotal=0;

[code]....

View 5 Replies View Related

C :: Program That Asks The User To Type 10 Integers Of Array?

Mar 2, 2014

Write a program that asks the user to type 10 integers of an array. The program will then display either "the array is growing", "the array is decreasing", "the array is constant", or "the array is growing and decreasing."

(Hint: compare consecutive numbers in array and check whether it is increasing or not or constant) I wrote the program very well, but do I have to use "bool" like in c++ ? I haven't known how to code in c++ yet.So, I don't want to use "bool" in C.

I also wrote code about it but it looks like backslash and one,two,three,four,five how can I do it like this ?

View 4 Replies View Related

C :: Program That Allow User To Enter A Number N And Print Nth Prime Number

Nov 3, 2013

I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....

EXAMPLE

user enters 55

printf("The 55th prime number is %i", variable");

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

Visual C++ :: Create A Program That Perform Same Calculation For Every Oscillation

Jan 17, 2014

I am reading from a text file and want to create a program that will perform the same calculation for every oscillation.

The text file I'm reading from is attached to this post. A3.txt

The program that I've written is as follows:

Code:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile ("AP1.txt");
ofstream results_file ("APDuration.txt");

[Code]...

Where I'm having trouble is in having the inFile.seekg function iterate to the next series of values.

Here is what the data file looks like in a graph:

In a nutshell, my program will read the duration of each action potential from a point called "dVmax" (where the upstroke is at its maximum upward rate of change) to the point of 90% repolarization (on the downstroke where 90% of the total wave amplitude is subtracted from the volts at peak amplitude).

If you would like to test my program on one action potential, here is one action potential : AP1.txt

View 8 Replies View Related

C++ :: Enter Multiple Strings Into Char Array

Feb 16, 2014

I am having issues getting this working. This is a simple program that is designed to ask a user if he would like to enter a string, if yes, the user is prompted to enter it and its stored in a char array. User is then asked if he wants to enter another string... Once user responds no, the program outputs the strings and the program ends...

Note: I'm using in.getline(myarray[i], MAX, ' '), to avoid white space problems if user enters a space. Lastly I would like the option of letting user enter any number of strings, but how would you do this when declaring the 2 dimensional char array?

#include <iostream>
#include <string>
using namespace std;
const int MAX = 81; //max char is sting is 80
int main(){
string y_n;
bool go = true;

[Code] ....

View 2 Replies View Related

C++ ::  make Program That Can Type String Into Another Window?

Apr 26, 2013

I am trying to make a program that can type a string into another window. I have gotten it to the point that it can type the string, just not correctly. It will type random numbers and not the given string. The key event uses ASCII code for the arguments, and I don't see anything wrong with my numbers. Here is the code I have so far.

#include "stdafx.h"
#include <iostream>
#include <windows.h>

[Code].....

View 2 Replies View Related

C++ :: Using Class Functions To Enter And Print Out Info

May 19, 2013

I have a program that uses class functions to enter and print out info. The problem is with the second function answers(). Here is the whole cpp file. In the answer function I need to use an exception to exit when its the end of an array. I could just be doing it wrong. I used try/catch originally but when I used it, it caught the exception but ended the whole program.

#include <iostream>
#include <cstdlib>
#include "answering_machine.h"
using namespace std;
void AnsweringMachine::init(){
numMessages = 0;

[Code] ......

View 6 Replies View Related

C :: Which Data Type Have To Enter To Get 12 Digit Numbers

Jul 8, 2013

I've seen some threads that include the information about what data types one has to use usually to put a number of 12digit. But honestly speaking none of them works for me & it takes me a lot suffering about the data type. Even I've googled but I didn't get any specific result.

So, which data type I'd have to use to enter 12digit number.

I'm writing a code to find the largest prime factor of the number 600851475143

View 4 Replies View Related

C :: How To Print Everything Type Till Hit Enter Using POINTERS

Mar 5, 2013

I think I need to use

Code:

while(input[0]!='
'){
scanf("%s", input)
printf("%s", pointerhere);
}

basically we were asked to make a program that will print everything before the user hits the enter button. we cannot use fgets and we have to use pointers here.

not sure what exactly to do. We were told not to use fgets cause it's so easy and we need to incorporate pointers in this project..

View 8 Replies View Related







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