My assignment: Write a program that prompts the user to enter 3 strings. The program then outputs 6 diffente ways to arrange the words.
Example: a, b, c can be arrange as
abc
cba
I created my program but it only reads sigle words like hi, hello but when i enter somenthing like
"Hello there"
"How are you"
then progam fails. What is the problem when entering this words separeated by space. How come the computer cannot read them.
#include %26lt;iostream%26gt;
#include %26lt;string%26gt;
using namespace std;
int main()
{
string word1;
string word2;
string word3;
cout %26lt;%26lt; "Enter a word: ";
cin %26gt;%26gt; word1;
cout %26lt;%26lt; "Enter a second word: ";
cout %26lt;%26lt; "Enter a second word: ";
cin %26gt;%26gt; word2;
cout %26lt;%26lt; "Enter a third word: ";
cin %26gt;%26gt; word3;
cout %26lt;%26lt; "The permutation of the words you have entered are: " %26lt;%26lt; endl;
cout %26lt;%26lt; word1 %26lt;%26lt;"-" %26lt;%26lt; word2 %26lt;%26lt; "-" %26lt;%26lt; word3 %26lt;%26lt; endl;
cout %26lt;%26lt; word2 %26lt;%26lt;"-"%26lt;%26lt; word3%26lt;%26lt; "-" %26lt;%26lt;word1 %26lt;%26lt;endl;
cout %26lt;%26lt; word3 %26lt;%26lt;"-"%26lt;%26lt; word2 %26lt;%26lt;"-"%26lt;%26lt; word1 %26lt;%26lt;endl;
please help!
Help with C++ program?
rather than
cin%26gt;%26gt;word1;
use
getline(cin,word1);
it will read the entire line and assign to word1...
Reply:to input words with space use
cin.getline(char , int size ,in delimiter character) function
this does not work with normal cin because it is delimited with space
sympathy flowers
Friday, July 31, 2009
I need help on basic C Programming?
I've been trying to understand the C language, but for some reason I can't grasp it. Are there any helpful books, software, or suggestions to help me understand C programming any better?
I need help on basic C Programming?
Hi,
Where is a will there is a way. So be concentrate in ur study. I think this one is starting trouble. Better u started with "Let Us C" book written by Yashwant Kanetkar. I love him C knowledge, additionaly he gave some excersize in that book. How many days u taken for study of C langugae, it is a SEA. My fav. and interested language is C.
Better start with tutor for starting...
Reply:I have posted some very small and tiny programs in the applications, so that the beginners can easliy understand the language and programming. See if it helps you,
http://www.myspace.com/my_technical_blog
I need help on basic C Programming?
Hi,
Where is a will there is a way. So be concentrate in ur study. I think this one is starting trouble. Better u started with "Let Us C" book written by Yashwant Kanetkar. I love him C knowledge, additionaly he gave some excersize in that book. How many days u taken for study of C langugae, it is a SEA. My fav. and interested language is C.
Better start with tutor for starting...
Reply:I have posted some very small and tiny programs in the applications, so that the beginners can easliy understand the language and programming. See if it helps you,
http://www.myspace.com/my_technical_blog
Will vitamin c help my daughter stop coughing, runny nose etc?
i was told that if i put liquid vitamin c in my daughter's juice bottles that it will help her to stop coughing as much and stop the runny nose she constantly has
Will vitamin c help my daughter stop coughing, runny nose etc?
Only time will make them go away, but if the symptoms aren't improving after a week, take her to a dr.
Reply:Be careful!! too much can cause liver damage. Putting in a little bit might help, however she just might have allergies. See a pediatrician first, before you do anything as it might cause more harm than good. Be careful what you give your kids, you never know how they will react to it.
Reply:yup... it wont stop completely... but will make the cold a bit more bearable...
Reply:the Vitamin C can prevent you form getting cold like symptoms but by the time you get it it is too late, you can take her to the doctors
Reply:Vitamin C will help prevent colds but will not stop the symptoms if they have already started. If you add oranges or pineapples to your daughters diet it will help her fight off colds in the future.
Reply:Sure... eat some oranges, strawberries, spinach, melon
Reply:Yes and take some NyQuil or DayQuill.
Will vitamin c help my daughter stop coughing, runny nose etc?
Only time will make them go away, but if the symptoms aren't improving after a week, take her to a dr.
Reply:Be careful!! too much can cause liver damage. Putting in a little bit might help, however she just might have allergies. See a pediatrician first, before you do anything as it might cause more harm than good. Be careful what you give your kids, you never know how they will react to it.
Reply:yup... it wont stop completely... but will make the cold a bit more bearable...
Reply:the Vitamin C can prevent you form getting cold like symptoms but by the time you get it it is too late, you can take her to the doctors
Reply:Vitamin C will help prevent colds but will not stop the symptoms if they have already started. If you add oranges or pineapples to your daughters diet it will help her fight off colds in the future.
Reply:Sure... eat some oranges, strawberries, spinach, melon
Reply:Yes and take some NyQuil or DayQuill.
Help with c++ program?
This is my 1st c++ course and i desparately in need of some help.I need a program that will print out the year with the most hurricanes. the program will input the name, month,and day the hurricane occur.please note this has to be multiple years say 2006,2005,2004 etc. I could do the program for 1 year but cannt do it for multiple years. also the hurricane has to occure in the season( june 1st to nov 1st). i appriciate any input. thanks in advance.
Help with c++ program?
Alright. Here's the deal.
Since this is your first course, here are some tricks.
If the program will have an input of name, month,and day the hurricane, then you will need 4 variables. A string and 3 integers.
How will you use them? How many times will you repeat the loop?
If you do not know how many times you want it to be repeated, then the wisest choice is a do/while. Otherwise, let the user tell you how many times it should be done.
You will make those 4 variables. They should be arrays, make sure they are big enough.
it will be something as simple as this:
let the user tell you how many times he want it to be repeated:
int timesToBeRepeated = 0;
cin %26gt;%26gt; timesToBeRepeated;
for ( int i = 0; i %26lt; timesToBeRepeated; i++ )
{
cout %26lt;%26lt;"Enter the Hurricane name: \n";
cin %26gt;%26gt; hurricaneName[i];
.
.
.
}
then, to print it out, just do something like this:
cout %26lt;%26lt;"Hurricane Name"%26lt;%26lt;" %26lt;%26lt;"Day"%26lt;%26lt;..%26lt;%26lt;endl;
then:
for ( i = 0; i %26lt; timesToBeRepeated; i++ )
cout %26lt;%26lt; hurricaneName[i] %26lt;%26lt;" "%26lt;%26lt;....%26lt;%26lt;endl;
Work out the rest, but that is pretty much it., Any doubt, contact me.
Reply:use an array that goes from 1-n where n is the number of years your data spans. Everytime a hurricane happens in that year, increment array[p] by 1 where p is the year of your data entry.
then loop from 1-n and look for the year with the biggest array[p] value
Help with c++ program?
Alright. Here's the deal.
Since this is your first course, here are some tricks.
If the program will have an input of name, month,and day the hurricane, then you will need 4 variables. A string and 3 integers.
How will you use them? How many times will you repeat the loop?
If you do not know how many times you want it to be repeated, then the wisest choice is a do/while. Otherwise, let the user tell you how many times it should be done.
You will make those 4 variables. They should be arrays, make sure they are big enough.
it will be something as simple as this:
let the user tell you how many times he want it to be repeated:
int timesToBeRepeated = 0;
cin %26gt;%26gt; timesToBeRepeated;
for ( int i = 0; i %26lt; timesToBeRepeated; i++ )
{
cout %26lt;%26lt;"Enter the Hurricane name: \n";
cin %26gt;%26gt; hurricaneName[i];
.
.
.
}
then, to print it out, just do something like this:
cout %26lt;%26lt;"Hurricane Name"%26lt;%26lt;" %26lt;%26lt;"Day"%26lt;%26lt;..%26lt;%26lt;endl;
then:
for ( i = 0; i %26lt; timesToBeRepeated; i++ )
cout %26lt;%26lt; hurricaneName[i] %26lt;%26lt;" "%26lt;%26lt;....%26lt;%26lt;endl;
Work out the rest, but that is pretty much it., Any doubt, contact me.
Reply:use an array that goes from 1-n where n is the number of years your data spans. Everytime a hurricane happens in that year, increment array[p] by 1 where p is the year of your data entry.
then loop from 1-n and look for the year with the biggest array[p] value
Need major help with a C# code?
I need to code a C# program with visual express 2005 that will find the average of all prime numbers between 2-100 and print the result at the end. Im having trouble figuring out how its going to sort out the prime numbers. therefore, i cant even get this lab started. i asked my professor and he gave me a response that didnt really help. here it is.
1. Loop intI from 2 to 100. (By definition, 1 is NOT a prime number.)
2. For each intI, do the following:
...a. Set blnPrime = True
...b. Loop intJ from 1 to (intI-1).
...c. For each intJ, do the following:
......(1) Check to see if intI divided by intJ would give a remainder of zero. If so, it'll mean that the number is divisible by that number, so the number is NOT a prime. If number is not a prime, we break out of this loop.
...d. If number is a prime, accumulate it in the sum total of all prime numbers, and add 1 to the count of prime numbers.
3. Print out all results and the average.
this is due tonight, someone please help!!
Need major help with a C# code?
using System;
using System.Collections.Generic;
using System.Text;
namespace prime
{
class Program
{
static bool isPrime(int n)
{
for (int i = 2 ; i %26lt; n; i++)
{
if ((n % i) == 0)
return false;
}
return true;
}
static void Main(string[] args)
{
int avg = 0;
int cpt = 0;
for (int i = 2; i %26lt; 101; i++)
{
if (isPrime(i))
{
avg += i; cpt++;
}
}
Console.Write(avg / cpt);
}
}
}
bridal flowers
1. Loop intI from 2 to 100. (By definition, 1 is NOT a prime number.)
2. For each intI, do the following:
...a. Set blnPrime = True
...b. Loop intJ from 1 to (intI-1).
...c. For each intJ, do the following:
......(1) Check to see if intI divided by intJ would give a remainder of zero. If so, it'll mean that the number is divisible by that number, so the number is NOT a prime. If number is not a prime, we break out of this loop.
...d. If number is a prime, accumulate it in the sum total of all prime numbers, and add 1 to the count of prime numbers.
3. Print out all results and the average.
this is due tonight, someone please help!!
Need major help with a C# code?
using System;
using System.Collections.Generic;
using System.Text;
namespace prime
{
class Program
{
static bool isPrime(int n)
{
for (int i = 2 ; i %26lt; n; i++)
{
if ((n % i) == 0)
return false;
}
return true;
}
static void Main(string[] args)
{
int avg = 0;
int cpt = 0;
for (int i = 2; i %26lt; 101; i++)
{
if (isPrime(i))
{
avg += i; cpt++;
}
}
Console.Write(avg / cpt);
}
}
}
bridal flowers
The a/c on my car blows out the defrost and floor only?...it was working fine all around days ago need help?..
well my car was blowing out of all vents days ago ....i try today to turn the a/c on and it only comes out the defrost and the floor im so confused i need help?........its a 1985 buick regal....v6 3.8
The a/c on my car blows out the defrost and floor only?...it was working fine all around days ago need help?..
it has a vacuum leak to the control valve
Reply:Yes,this is vacuum hose broken under the hood.Open hood and look close to one of the corners close to firewall.You'll see one of the plastic vacuum hoses is broken.Get small rubber hose and splice it.That will fix your problem.
The a/c on my car blows out the defrost and floor only?...it was working fine all around days ago need help?..
it has a vacuum leak to the control valve
Reply:Yes,this is vacuum hose broken under the hood.Open hood and look close to one of the corners close to firewall.You'll see one of the plastic vacuum hoses is broken.Get small rubber hose and splice it.That will fix your problem.
I'm clueless with this c program! someone please help me...?
Develop a C program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:
a. Account number
b. Balance at the beggining of the month
c. Total of all items charged by this customer this month
d. Total of all credits applied to this customer's account this month
e. Allowed credit limit
The program should input each of these facts, calculate the new balance (=beginning balance + charges - credits), and determine if the new balance exceeds the customer's credit limit. For those customers whose credit limit is exceeded, the program should display the customer's account number, credit limit, new balance and the message "Credit limit exceeded."
i can't seem to know were to start from or what to do
please help me...
spare my poor soul
thanks
thanks
thanks
thanks
I'm clueless with this c program! someone please help me...?
#include%26lt;iostream.h%26gt;
int main(void)
{
int acctNumber;
float creditLimit;
float startBalance;
float endBalance;
float monthCharges;
float monthCredits;
printf("Enter the following info:\n\n\n");
printf("Enter account number:\n");
scanf("%d",%26amp;acctNumber);
printf("Enter credit limit:\n");
scanf("%d",%26amp;creditLimit);
printf("enter begining balance:");
scanf("%d",%26amp;startBalance);
printf("enter monthly charges:");
scanf("%d",%26amp;monthCharges);
printf("enter monthly Credits:");
scanf("%d",%26amp;monthCredits);
endBalance = startBalance + (monthCharges - monthCredits);
printf("Account No. %d, credit limit is %d; current balance is %d\n", acctNumber, creditLimit, endBalance);
if(endBalance %26gt; creditLimit) {
printf("Credit limit exceeded.\n");
}
return 0;
}
a. Account number
b. Balance at the beggining of the month
c. Total of all items charged by this customer this month
d. Total of all credits applied to this customer's account this month
e. Allowed credit limit
The program should input each of these facts, calculate the new balance (=beginning balance + charges - credits), and determine if the new balance exceeds the customer's credit limit. For those customers whose credit limit is exceeded, the program should display the customer's account number, credit limit, new balance and the message "Credit limit exceeded."
i can't seem to know were to start from or what to do
please help me...
spare my poor soul
thanks
thanks
thanks
thanks
I'm clueless with this c program! someone please help me...?
#include%26lt;iostream.h%26gt;
int main(void)
{
int acctNumber;
float creditLimit;
float startBalance;
float endBalance;
float monthCharges;
float monthCredits;
printf("Enter the following info:\n\n\n");
printf("Enter account number:\n");
scanf("%d",%26amp;acctNumber);
printf("Enter credit limit:\n");
scanf("%d",%26amp;creditLimit);
printf("enter begining balance:");
scanf("%d",%26amp;startBalance);
printf("enter monthly charges:");
scanf("%d",%26amp;monthCharges);
printf("enter monthly Credits:");
scanf("%d",%26amp;monthCredits);
endBalance = startBalance + (monthCharges - monthCredits);
printf("Account No. %d, credit limit is %d; current balance is %d\n", acctNumber, creditLimit, endBalance);
if(endBalance %26gt; creditLimit) {
printf("Credit limit exceeded.\n");
}
return 0;
}
Subscribe to:
Posts (Atom)