C++ :: How Is A Program Written To Ignore Case Sensitivity When Dealing With Input

Nov 9, 2014

I've written a simple program, which asks the user to respond to a YES or NO question using the character Y/y for YES and the character N/n for NO. The foundation of this program is based around several IF statements implemented to aid in finding the ASCII value of the character entered before invoking the corresponding cout statement that informs the user which character they entered. My Question: How should a program be written to deal with ignoring case sensitivity in regards to the users' input?

Here is my amateurish attempt,

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

[Code] .....

The following are IF statements written for the program to determine whether the user answered YES or NO. The program then performs the cout statement that contains the corresponding character to the ASCII value found.

*/
if(user_input == 121 || user_input == 89)
{
if(user_input == 121)
{
cout << "

[code]......

View 2 Replies


ADVERTISEMENT

C/C++ :: How To Ignore Case Sensitive While Comparing Each Character

Sep 26, 2014

The following Program ask a user to input a sentence. Program alphabetically sort individual character for each word.

My problem is, how do I ignore case sensitive if a user enters a uppercase letter. I try using stricmp but ran into some errors.

Below code:

#include <iostream>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
void bubblesort(char a[]);
int main() {
char sent[50];

[Code] ....

Current output:
input: today is a great day
output: adoty is a aegrt ady

Using Uppercase:
input: Today is a Great Day
output: Tadoy is a Gaert Day

What I want:
input: Today is a Great Day
output: adoTy is a aeGrt aDy

View 6 Replies View Related

C/C++ :: General Protection Exception Is Written When Execute Program

May 8, 2012

My code in c++ is

#include<iostream.h>
main()
{int a[10],x[5];
a[-7]=15;
x[5]=20;
cout<<x[-5];
}

View 2 Replies View Related

C Sharp :: Convert Log Parsing Program Written In Perl

Feb 13, 2013

Following is a script written in perl :

#Number of bugs edited in Watson Express  
#find server*/watson*/log/ -name "watson*" -type f  -newer  ./tmpoldfile ! -newer  ./tmpnewfile  | 
xargs grep "WX Edit Bug" | awk '{print $8}' | sort | uniq  | wc -l  
// 

this is log parsing string in perl based on bash file.

Need a log parsing program in C# for the same.....

View 1 Replies View Related

C :: Struct Written In A Program That Writes To A Report Text File

May 3, 2013

I'm writing a program that writes to a report in a text file. It uses a struct but with no array. How can I write this so that the report comes out as it should because as of now after i removed the brackets from record which is the variable of the struct my report isn't printing right.

View 8 Replies View Related

C :: How To Make A Switch Case Loop After Input Entered

Dec 31, 2013

I'm working on a code that needs to loop a switch case back to the beginning after a certain input is entered.

ex) Code:

printf("Select an option);
printf("1. Play game");
printf("2. Status");
printf("3. Exit");
scanf("%i", &userinput);
switch(userinput);

[Code]...

For my program, I want option 2 to display something, then loop back to "select and option" after the user presses enter. How would I write that? Would i use a while? do while?

View 3 Replies View Related

C++ :: Input String And Then Convert Each 1st Letter Of Word Into Capital Case

Dec 10, 2014

Write a program that inputs a string and then converts each 1st letter of a word in the string into capital case. An example run of the program is shown below:

Enter string: introduction to programming
Output string: Introduction To Programming

View 1 Replies View Related

C++ :: Convert Input String Into A Form - Capital And Lower Case Letters

Mar 27, 2013

How can I write program that can convert an input string into a form that only the first letter of the string is a capital letter and the rest is lower-case?

View 3 Replies View Related

C :: How To Get Upper Case And Lower Case Equal

Feb 18, 2015

I just dont know how to get my upper case and lower case equal...heres the program: Write a program to calculate utility cost for ACME UTILITY COMPANY. The company has 3 types of customers (R) residential, (C) Commercial and (G) government. Customers are billed based on the number of kilowatts used and they type of customer they are (R,C,or G).

Residential cusstomers are charged 0.25 cents per kilowatt hour for the first 500kw used, and 0.35 cent per kwh for all kw used over 500.Commercial customers are charged 0.22 cents per kilowatt hour for the first 999kw used, 0.29 cents per kwh for all kw used over 999 kw up to 1999 and 0.45 cents per kwh for all kilowatts used greater than 1999. Commercial customers that use over 2000 kw are charged a special surcharge of 100.0 in addition to the regular charges.

Government customers are charged 0.34 cents for the first 1500 kwh used(<=1500). 0.30 cent for the next 1000 kwh(1501-2500) and 0.25 cents for all kwh used over (>=2501)

in addition residential customer are charged .5% tax on the cost utilities while Commercial customers are 5% tax on the cost of utilities not including the special surcharge Government customers are not charged a tax

Code:

#include <stdio.h>
#include <math.h>
int main(void)
{
int R;
int ct;
int kwh;
int taxes;
int surcharge;
int charge
}

[code].....

the program should quit with Q and calculate the amount owed, utility charge, and surcharge

View 8 Replies View Related

C :: Program Keeps On Crashing When It Finishes Case 1?

Oct 18, 2013

The program keeps on crashing when it finishes case 1

View 5 Replies View Related

C++ :: Menu Program As Switch-Case Structure

Feb 13, 2015

I tried to write a menu program as a switch-case structure with a separate function for a switch-case structure itself. The outcome for it currently is an undesired one

Code:

#include <iostream>
using namespace std;
int menu(int answer);
int main()

[Code].....

The output I get is one where it's just an infinite loop of "Bad choice! Please try again later.".

View 7 Replies View Related

C++ :: String Comparison - Case Insensitive Program

Feb 20, 2014

So I have started this program for class but am stuck on what to do next. Basically you need to create a function to compare 2 strings (case-insensitive). The strings shouldn't be altered and the return value should be similar to strcmp.

This is my main file

#include <iostream>
//#include <cstring>
#include <iomanip>
#include "rpstrings.h"
using namespace std;
int main () {
char Str1[20], Str2[20];
short result;

[Code] .....

I don't know if I labeled the files correct. what I need to do is to add 2 defaulted arguments which will allow the user to request that you skip spaces and/or skip punctuation when doing the comparison.

Also, how I can sort the numbers when they aren't justified with leading 0's and if they aren't in the lead string (kinda of like the natural sort).

View 2 Replies View Related

C++ :: Switch Case - Program That Calculates Students Grade

Apr 18, 2013

Trying to write a program that calculates a students grade based on how many assignments have been graded. I am using a switch case since there is a total of 5 assignments, however when I enter case 1, and enter in how many I got out of 100, it just closes the program it doesn't go to the next part.

#include <iostream>
using namespace std;
char calculategrade(int total);
int main() {
// local variable declaration:
char input;

[Code]....

View 6 Replies View Related

Visual C++ :: Program To Reverse Sentence - Case Sensitive

May 31, 2014

I have to write a program to reverse a sentence like

cat
tac

but my program is case sensitive. Like if i enter sentence it gives me ecntenes(which is wrong). How to make it non case-sensitive using vectors? (I cannot use #algorithims)

// BackWardsSentence.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
string BackWords (string sentence);
int BackSentence (string sentence);

[Code] .....

View 2 Replies View Related

Visual C++ :: Reverse Sentence - How To Make Program Non Case-sensitive Using Vectors

May 25, 2014

I had been tasked to create a program that reverses a word i.e.

cat
tac

How to make my program non case-sensitive using vectors?

Code:
// BackWardsSentence.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
string BackWords (string sentence);
int BackSentence (string sentence);
string BackWords1 (string sentence);

[Code] .....

View 2 Replies View Related

C# :: Dealing With Localized Strings

Aug 20, 2014

So, I finally got translations for all the strings I'm using. However, depending on the language, the strings can exceed the space of the user controls, tabs, buttons, etc.. So in some parts, the words are either completely cut off or the word itself is cut off midway and finishes on another line.

I am wondering what is generally done about languages that use really long strings?

Should I reduce the font size or use multiline? Are there any best practices for this scenario?

This is for a WPF project.

View 5 Replies View Related

C :: Dealing A Deck Of Cards Using Structs?

Sep 9, 2013

I have a deck of 108 cards inside a 2D array and want to deal these card by 7 to 4 player. Each player had a id. The player and id are stored in a file while i've read in array each. Now I have to deal the cards.

Code:

struct card{
char color;
int rank;
char action[24];
char location[108]; Code: struct players{char name[10];
int id[5];
char hand;
};

View 2 Replies View Related

C++ :: Dealing With 2D Array Inside A Function

Apr 16, 2014

I have a problem with pointer array, i passed a 2d array to a function but then i dont know how to make operations on it !!!

#include <iostream>
using namespace std;
int fun_name (int * arr) {
for (int i = 0;i< ??? ;i++) // how to compare while i don't know the size of array!!

[Code] ....

View 2 Replies View Related

C++ :: Dealing With Signed / Unsigned Mismatch

Oct 18, 2014

There are many questions on the web on how to fix a specific signed/unsigned mismatch, and the solution is usually just making one variable unsigned.

I have a grid (x,y) which should be unsigned, since you can't have a (-5,-3) sized grid. However, I have a Direction object which should be signed, since I can have a (-1, -1) direction. The problem is when I do something like Location_x + Direction_x > grid_x which throws the signed/unsigned mismatch warning.

View 13 Replies View Related

C++ :: Dealing With Operator Overload Function Failure

Aug 23, 2014

Say I have a class that requires dynamic allocation to implement a few of the operators. Take "+" for example; I need to create a new object to hold the sum of the two parameters whose size is not known at compile time.

I'm pretty sure the standard way to indicate a failure inside the overloading function would be to throw an exception. However I am currently involved in an embedded(ish) project where the spec. says no exceptions are to be used.

I think I have 2 options:

1. Return an "invalid" object (with a flag indicating an error has occurred) and check for this after each operation.

a = b + c
if (a.err)
// handle error
or

2. To forsake operator overloading entirely and think up a new way of doing things where all functions that involve dynamic allocation can return error codes. but this seems rather terrible too as I may end up with something like:

objA a
if (add(&a, b, c) == -1) // assuming b and c are initialized before this snippet starts
// handle error

Is there a number 3 that I haven't thought of? It seems that not allowing exceptions is fairly common even in the non-embedded world [URL] so how is this normally done? or is operator overloading usually avoided when exceptions are not allowed?

View 3 Replies View Related

C :: How To Ignore All Key Presses On Keyboard Except 1-5

May 7, 2014

Here is the function I am trying to modify...

Code:
void DisplayAdminMenu() {
char ch;
system("cls");
printf("Admin Menu");

[Code] ......

Error! Must enter a number between 1 and 5

View 6 Replies View Related

C/C++ :: How To Ignore Certain Characters In A String

Sep 18, 2014

I am trying to cout just the first 5 characters the user enters into a string. I'm not sure how I can discard or not show the rest of the characters they try to enter after 5.

#include <iostream>
#include <string>
using namespace std;
int main() {
string random;
cout << "Enter any word." << endl;
cin >> random;
cout << random; //want to ignore everything after first 5 characters entered.
return 0;
}

View 1 Replies View Related

C++ :: Ignore Code When Compiling?

Sep 7, 2012

In a rather large codebase, there is a set of recurring calls to a couple vararg functions (mainly for logging)

Code: logthis(foo, bar(), somefunction(parameter1,parameter2), somethingelse);

The number of parameters to this function is variable It has all types of variables, function calls, etc.

The code has thousands of these lines

There is now a need for a special version of the compile that will remove a lot of the code, among others is the logging.

Can I somehow #define the "logthis" name into something that'll remove all actual calls to the code. including the actual parameters/expressions to the call.

I can't afford to add #ifdef/#endif around each of the calls because there are too many of them, and because that'll cause some undisired side effects in our code conformance tests.

Code: #define logthis __noop

comes close, that removes the call, but it still causes the compiler to evaluate and validate all the parameters to the logthis function, which doesn't work because in this case, removing the logging headers also removes other members of the class that get used as part of the parameters to logthis()

if I could define logthis into // resulting in all the rest of the line being comments, but that doesn't work.

Preferably I'd like something to be portable, but I'll take a solution that only works on visual studio as well.

View 6 Replies View Related

C++ :: Dealing With Dynamic Arrays - Printing Initialized Objects

Jul 15, 2013

I have a problem in dealing with dynamic arrays. I have initialized the objects and now i want to print them.

Code: // main
char* namesList[] = {"Brad Shaw","Aimen Adams","Sal Dimitry","Cristi Anreaz","Poala James"};
int idList[]={232,444,135,52,134};
Team t1( namesList,idList,5,"waqas");
t1.Print_team(); My class Team looks something like this:

[Code] ....

The print function does not work. I have to implement the print function without taking any parameters.. How should i do that ?

View 9 Replies View Related

C/C++ :: Deal 2 Hands Of Cards - Print Deck After Dealing

Apr 2, 2014

My assignment is to create a program to print a deck of 52 cards, shuffle it, deal 2 hands of 5 cards, then print the deck after dealing the 2 hands with the cards that were dealt removed. this is my code so far...

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define DECK_SIZE 52
void init_deck( int deck[] , int size ) ;
void shuffle_deck( int deck[] , int size ) ;

[Code] ....

I am having trouble dealing 2 random hands and how to print the deck with the cards removed.

View 3 Replies View Related

C :: Ignore Negative Numbers In Array

Feb 15, 2014

So i have this program that takes in user input and stores them into an array and then prints them, removes duplicates, and sorts in ascending order. The user can also stop by inputting a sentinel value (in this case -1). But i am also supposed to ignore any negative value besides -1. When i input any other negative value into the program it messes up. How would i go about ignoring the negative values?

Code:
#include<stdio.h>
int main()
{
int input, nums[20], i, j, k, temp, count=0, count2=0;
for(i=0;i<20;i++)

[Code] .....

View 8 Replies View Related







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