| | |
wrong output
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 14
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main( ) { float rand, cent, pounds, shillings; cout << "Enter Pounds " << endl; cin >> pounds; cout << "Enter Shillings " << endl; cin >> shillings; pounds =1; shillings =1; // enter amount while both pounds and shillings is not equal to 0 while (pounds != 0 && shillings != 0) { cout << "Enter Pounds " << endl; cin >> pounds; cout << "Enter Shillings " << endl; cin >> shillings; // Calculate & convert pounds to rands rand = (pounds * 2 ); // Calculate & convert shillings to cent cent = (shillings * 10); cout << "The pound is equal to R "<<rand << endl; cout <<"Shillings equells to "<< cent << " C "<< endl; } return 0; }
Last edited by Ancient Dragon; May 3rd, 2008 at 3:41 pm. Reason: add code tags
•
•
Join Date: Apr 2008
Posts: 14
Reputation:
Solved Threads: 0
Ok Ancient Dragon
The program has to convert pounds to rands, and also convert shillings to cents also display the results. Asuming that there are 20 shillings in a pound and that 1 shilling to 10 cents.
The program to run in each line the first entry is the number of pounds and the second entry is the number of shillings.
please help
The program has to convert pounds to rands, and also convert shillings to cents also display the results. Asuming that there are 20 shillings in a pound and that 1 shilling to 10 cents.
The program to run in each line the first entry is the number of pounds and the second entry is the number of shillings.
please help
•
•
Join Date: Jan 2008
Posts: 3,813
Reputation:
Solved Threads: 501
•
•
•
•
Ok Ancient Dragon
The program has to convert pounds to rands, and also convert shillings to cents also display the results. Asuming that there are 20 shillings in a pound and that 1 shilling to 10 cents.
The program to run in each line the first entry is the number of pounds and the second entry is the number of shillings.
please help
http://www.cplusplus.com/reference/c...dlib/rand.html
You haven't included cstdlib, but you have said that you are using the standard namespace in line 2. If you get some error regarding "rand", that may be why. You can change it to something different.
You have pounds and shillings declared as floats. It can be dangerous to compare floats to an exact number as you have in line 18. However, since you are comparing them to 0, it's probably all right.
•
•
Join Date: Jan 2008
Posts: 3,813
Reputation:
Solved Threads: 501
•
•
•
•
VernonDozier
I have made the changes but the program still gives wrong output
please anyone help
•
•
Join Date: Apr 2008
Posts: 14
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> using namespace std; int main() { int Rand, Cent, Pounds, Shillings; // pound = 20 shillings do { cout << "Enter Pounds: " << endl; cin >> Pounds; cout << "Enter Shillings: " << endl; cin >> Shillings; } while (Pounds != 0 && Shillings != 0); { // Calculate & convert pounds to rands Rand = (Pounds * 2 ); // Calculate & convert shillings to cent Cent = (Shillings * 10); cout << "The pound is equells to R "<<Rand << endl; cout <<"Shilling equells to "<< Cent<< " C "<< endl; } return 0;#include <iostream> #include <cstdlib> using namespace std; int main() { int Rand, Cent, Pounds, Shillings; // pound = 20 shillings do { cout << "Enter Pounds: " << endl; cin >> Pounds; cout << "Enter Shillings: " << endl; cin >> Shillings; } while (Pounds != 0 && Shillings != 0); { // Calculate & convert pounds to rands Rand = (Pounds * 2 ); // Calculate & convert shillings to cent Cent = (Shillings * 10); cout << "The pound is equells to R "<<Rand << endl; cout <<"Shilling equells to "<< Cent<< " C "<< endl; } return 0;
Can anyone help please
This program only input the first input and stops, which is 12 pounds and 0 shillings
can you assist me so that program can input the other inputs
pounds & shillings
1 & 19
0 & 11
22 & 18
9 & 8
0 & 0 (ending)
Last edited by Ancient Dragon; May 4th, 2008 at 6:50 pm. Reason: replaced quote tags with code tags
•
•
Join Date: Jan 2008
Posts: 3,813
Reputation:
Solved Threads: 501
•
•
•
•
Can anyone help please
This program only input the first input and stops, which is 12 pounds and 0 shillings
can you assist me so that program can input the other inputs
pounds & shillings
1 & 19
0 & 11
22 & 18
9 & 8
0 & 0 (ending)
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> using namespace std; int main() { int Rand, Cent, Pounds, Shillings; // pound = 20 shillings do { cout << "Enter Pounds: " << endl; cin >> Pounds; cout << "Enter Shillings: " << endl; cin >> Shillings; } while (Pounds != 0 && Shillings != 0); { // Calculate & convert pounds to rands Rand = (Pounds * 2 ); // Calculate & convert shillings to cent Cent = (Shillings * 10); cout << "The pound is equells to R "<<Rand << endl; cout <<"Shilling equells to "<< Cent<< " C "<< endl; } return 0;
return 0; to end the main function. The brackets on lines 17 and 27 don't hurt, but they don't do anything either so you can delete them. Your do-while loop is from lines 9 - 16. It reads in data repeatedly but doesn't do any of the calculations. It will continually ask for input until it gets two zeroes. Then and only then will execute the calculation code. This calculation code will only execute once since it is not in a loop. Thus, if you want the calculation code to execute each time the user enters data, you are ending the do-while loop too soon. End it right above return 0; . So delete lines 17 and 27, move lines 15 and 16 to right after line 25, and add a closing bracket after return 0; . it would help if you would learn how to format your code better.
As you can now see, the loop continuously asks for the #Pounds and Shillings until one or the other is 0. Each time you enter the amounts the previous amounts are destroyed. You probably should move lines 16-20 up inside the loop, after line 10.
C++ Syntax (Toggle Plain Text)
int main() { int Rand, Cent, Pounds, Shillings; // pound = 20 shillings do { cout << "Enter Pounds: " << endl; cin >> Pounds; cout << "Enter Shillings: " << endl; cin >> Shillings; }while (Pounds != 0 && Shillings != 0); // Calculate & convert pounds to rands Rand = (Pounds * 2 ); // Calculate & convert shillings to cent Cent = (Shillings * 10); cout << "The pound is equells to R "<<Rand << endl; cout <<"Shilling equells to "<< Cent<< " C "<< endl; return 0; }
As you can now see, the loop continuously asks for the #Pounds and Shillings until one or the other is 0. Each time you enter the amounts the previous amounts are destroyed. You probably should move lines 16-20 up inside the loop, after line 10.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- plz help i dont know what am i doing wrong (C++)
- wrong output , but i am sure that code is correct (Assembly)
- wrong output (C++)
- wrong output in c program (C++)
Other Threads in the C++ Forum
- Previous Thread: Produce output
- Next Thread: visual c++ 2003
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






