473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need help replacing text

35
Struggling greatly here with C++ but I find it interesting at the same time. Any good books to buy or web sites to help with this program?

For the following - I'm suppose to replace the first three statements with cin and cout statements so that the values for the age, salary, and distance_to_the_moon can be obtained from the user. This make the program flexible so that everytime is is run different numbers are used.

#include <iostream.h>
void main(void)
{
int age = 32;
float salary = 25000.75;
long distance_to_the_moon = 238857;
cout << “The employee is “ << age << “ years old” << endl;
cout << “The employee makes $” << salary << endl;
cout << “The moon is “ << distance_to_the_moon <<
“ miles from the earth” << endl;
}
# comments appear at the top of the file indicating the assignment number question number and your name
# the tax amount is a constant value of .085
# the user enters from the keyboard the cost
# a discount of 10% will be declared as a constant and given on the cost that was entered
# a new variable will be declared called new_cost and will be the cost minus the discount
# the tax will be figured out on the new_cost after the discount of 10% is taken off of the cost
# the total will be the new_cost plus the tax
# the user will enter the amount_paid from the keyboard
# the change will be the amount_paid minus the total
# and the cost, discount, new cost, tax, total, and amount_paid will all be printed with appropriate format.
# include <iostream.h>
void main()
{
float cost = 15.50; // The cost of an item
float sales_tax = 0.06; // Sales tax is 6 percent
float amount_paid = 20.00; //The amount the buyer paid
float tax, change, total; // Sales tax, buyer change and total bill
tax = cost * sales_tax;
total = cost + tax;
change =amount_paid – total;
cout << “Item Cost: $” << cost << “ Tax: $” << tax <<
“\tTotal: $” << total << endl;
cout << “Customer change: $” << change << endl;
}
Sep 10 '06 #1
11 3037
Banfa
9,065 Expert Mod 8TB
In the first problem I feel sure that you can attempt to replace the declaration and assigment of a variable with the declaration of a variable and cout and cin statements to aquire the variables value.

cin works as

Expand|Select|Wrap|Line Numbers
  1. int value;
  2.  
  3. cin >> value;
  4.  
  5. cout << "The value entered was: " << value << "\n";
  6.  

In the second you have very clearly not followed the bullet points you have been given. Salves tax 0.085 (8.5%), cost_new variable = cost minus discount. I suggest you start by correcting these simple errors.
Sep 10 '06 #2
05l8kr
35
I sent you a PM
Sep 10 '06 #3
05l8kr
35
Errors! I got 37 errors for the first problem, how can I correct these errors?
Sep 10 '06 #4
05l8kr
35
I made some changes and I am still getting 28 errors! It's improvement over 37 but still a lot of problems. Updated code so far -
Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. void main(void)
  3. {
  4. int age = 32;
  5. float salary = 25000.75;
  6. long distance_to_the_moon = 238857;
  7. cout << The employee is  << age << “ years old” << endl;
  8. cout << The employee makes $ << salary << endl;
  9. cout << The moon is  << distance_to_the_moon <<
  10. cout << miles from the earth << endl;
  11. }
Sep 10 '06 #5
Banfa
9,065 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. cout << The employee is  << age << “ years old” << endl;
  2.  
should be

Expand|Select|Wrap|Line Numbers
  1. cout << "The employee is"  << age << “ years old” << endl;
  2.  
You've made similar errors in all the other cout statements
Sep 11 '06 #6
05l8kr
35
Expand|Select|Wrap|Line Numbers
  1. cout << The employee is  << age << “ years old” << endl;
  2.  
should be

Expand|Select|Wrap|Line Numbers
  1. cout << "The employee is"  << age << “ years old” << endl;
  2.  
You've made similar errors in all the other cout statements
I fixed it and I'm going to try second problem now.
Sep 11 '06 #7
05l8kr
35
I am stuck on the second part of the problem, I can't figure out what else is needed to be done. I keep getting three errors.

Expand|Select|Wrap|Line Numbers
  1. //
  2. //
  3. # include <iostream.h>
  4. void main()
  5. {
  6. float cost = 15.50; // The cost of an item
  7. float sales_tax = 0.06; // Sales tax is 6 percent
  8. float amount_paid = 20.00; //The amount the buyer paid
  9. float tax, change, total; // Sales tax, buyer change and total bill
  10. tax = cost * sales_tax;
  11. total = cost + tax;
  12. change =amount_paid  total;
  13. cout << "Item Cost:" "$" << cost <<  Tax: $ << tax <<
  14. tTotal: "$" << total << endl;
  15. cout << "Customer change:" "$" << change << endl;
  16. }
Errors
Expand|Select|Wrap|Line Numbers
  1. cpp2.cpp(7) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
  2. cpp2.cpp(12) : error C2146: syntax error : missing ';' before identifier 'total'
  3. cpp2.cpp(13) : error C2065: 'Tax' : undeclared identifier
  4. cpp2.cpp(13) : error C2143: syntax error : missing ';' before ':'
  5. Error executing cl.exe.
  6.  
  7. Cpp2.obj - 3 error(s), 1 warning(s)
  8.  
I am suppose to.....
# comments appear at the top of the file indicating the assignment number question number and your name
# the tax amount is a constant value of .085
# the user enters from the keyboard the cost
# a discount of 10% will be declared as a constant and given on the cost that was entered
# a new variable will be declared called new_cost and will be the cost minus the discount
# the tax will be figured out on the new_cost after the discount of 10% is taken off of the cost
# the total will be the new_cost plus the tax
# the user will enter the amount_paid from the keyboard
# the change will be the amount_paid minus the total
# and the cost, discount, new cost, tax, total, and amount_paid will all be printed with appropriate format.
Oct 4 '06 #8
Banfa
9,065 Expert Mod 8TB
This warning

cpp2.cpp(7) : warning C4305: 'initializing' : truncation from 'const double' to 'float'

relates to this code line

float cost = 15.50; // The cost of an item

a floating point literal (15.50 in this case) has type double. When you assign it to a float you are loosing precission hence the warning. You can declare a floating point literal of type float by appending an F to the number.

float cost = 15.50F; // The cost of an item

This will remove this warning


This error

cpp2.cpp(12) : error C2146: syntax error : missing ';' before identifier 'total'

relates to this line of code

change =amount_paid total;

I would say that you have left out a minus sign, you should be able to spot something like this.

change =amount_paid - total;

These errors

cpp2.cpp(13) : error C2065: 'Tax' : undeclared identifier
cpp2.cpp(13) : error C2143: syntax error : missing ';' before ':'

relate to this line of code

cout << "Item Cost:" "$" << cost << Tax: $ << tax <<

You have left out the quotes round the Tax: $ string

cout << "Item Cost:" "$" << cost << "Tax: $" << tax <<
Oct 4 '06 #9
05l8kr
35
Expand|Select|Wrap|Line Numbers
  1. Cpp2.cpp(14) : error C2065: 'tTotal' : undeclared identifier
  2. \Cpp2.cpp(14) : error C2143: syntax error : missing ';' before ':'
  3. Error executing cl.exe.
  4.  
  5. Cpp2.obj - 2 error(s), 0 warning(s)
Expand|Select|Wrap|Line Numbers
  1. tTotal: "$" << total << endl;
What I'm I missing?
Oct 4 '06 #10
Banfa
9,065 Expert Mod 8TB
What I'm I missing?
More "
.
Oct 4 '06 #11
05l8kr
35
Got it, thanks for all your help
Oct 4 '06 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
6
by: Jerry Werner | last post by:
I need to replace my email address on hundreds of web pages with a new address (in a graphic, not a mailto) in order to thwart the email harvesters that spammers are using. Ideally, I'd like to do...
6
by: Peter Foti | last post by:
I have seen lots of examples where some HTML text is replaced with a background image using CSS. For example, replacing the text of an <h1> with a graphical logo, like so: CSS: h1 span {...
7
by: Rob Meade | last post by:
Hi all, Been a long time since I've been here... /me waves to all.. Ok - my conundrum.. I have a form where a user can enter text and BB codes...for example:
10
by: Nemok | last post by:
Hi, I am trying to write an additive encryption algorithm in C++ that will encrypt a text by adding a random numer to each character in a string. The code looks similar to this: for(int...
32
by: FireHead | last post by:
Hello C World & Fanatics I am trying replace fgets and provide a equavivalant function of BufferedInputReader::readLine. I am calling this readLine function as get_Stream. In the line 4 where...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
2
by: gsuns82 | last post by:
Hi all, I have to replace accented characters from a input string with normal plain text.I have coded as follows. String input = "ÄÀÁÂÃ"; input=...
4
by: wildman | last post by:
RE: Replacing Text without changing case?? This code works great, but case has to be exact. Research.Text = Research.Text.Replace(textboxSearch.Text, "<b>" + textboxSearch.Text + "</b>") ...
5
by: sameeradamle | last post by:
I need to write a perl script to replace text in a series of files. What i need to do: 1) in Command line i need to specify the <text to be replaced> , <replacing text>, <name of the files in which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.