Sorry,
was too tired to realize where i was posting
thanks for heads up
Salem commented: a) you should have posting this first then, and b) it's about time you learnt about code tags -4
Sorry,
was too tired to realize where i was posting
thanks for heads up
Hello,
I am writing the code for my basic calculator program and having some issues with it.
I keep getting the same error, which doesn't let even let me see whether my program works. Could you please take a look at it and at least direct me in a direction? Any help will be appreciated
here is my code:
#include<cmath>
#include<iostream>
#include<string>
using namespace std;
// Functions prototypes
void instruct();
char displayMenu(char);
float do_next_op(char, float, float);
int main()
{
char Q, q;
char choice; // option to the user to quit or to continue
char oper;
float accumVal;
float num;
// Instructions function
instruct(); // Greetings and Instructions
accumVal = do_next_op(oper, num, accumVal);
cout << "Please enter the operator first and then the number or type q or Q to exit the program: " << endl;
cin << oper;
do
{ cout << accumVal << endl;
} while (oper != 'q' || oper != 'Q');
cout << "Your Final Result is: " << accumVal << endl;
//cout << "Please type in your choice: " << endl;
//cin >> choice; //choice = displayMenu(choice); // Menu function call
system("pause");
return 0;
}
// Functions defenitions
float do_next_op(char operat, float num, float accumVal)/*The function below deteremines the
user input and does the appropriate calculations*/
{
cout << "Please choose your command: " << operat << endl;
cin >> operat;
switch(operat)
{
case 'q': case 'Q':
cout << "Your Final Result is: " << accumVal << "Thank you for using …
thank you
i will try it
Hello,
i have wrote a program using the while loop but it crashes whenever i run it
Basically, the goal of a program is to calculate the population of a town with constant 10% growth annually and then find how many years left.
here is my code (any help will be appreciated)
//Program1
// Chapter 5.4
#include<iostream>
using namespace std;
int const INITPOP = 900;
int const FINALPOP = 20000;
// prototype
int main()
{
int peopleCount;
float annualPerc = .1;
float yearsLeft,
annualGrowth;
peopleCount = INITPOP;
while (peopleCount < FINALPOP)
{
annualGrowth = annualPerc * INITPOP;
peopleCount = annualGrowth + INITPOP;
yearsLeft = FINALPOP / peopleCount;
peopleCount += peopleCount;
cout << peopleCount << yearsLeft << endl;
}
system("pause");
return 0;
}
I know, i messed up yesterday :)
wasnt thinking well
Also, I've been thinking if i really need to promt the user to input value of x
How can i make the program to get those int values from 1 to 5 and display all of them?
OH YOU ARE RIGHT!
i see i guess i didnt understood the exercise...
Thank you
thank you very much!
Hello,
Here is the problem ive been working on:
write a while loop that displays each int from 1 to 5 together with its square and a cube. Display all three values for integer on a separate line.
My problem is that it does not really do what it is asked to do.
here is my code:
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
int count;
int x;
float xsquared;
float xcubed;
cout << "enter the value for x: " << endl;
cin >> x;
count = 0;
while (count < 4)
{
xsquared = x * x;
xcubed = x * x * x;
cout << xsquared << xcubed <<endl;
count = count + 1;
}
system("pause");
return 0;
}
Thank you ahead of time
I asked for help not for giving me a hard time
but here is what i've got so far
// File:
// (description)
//
// Input:
// Output
//--------------------------------
// Class: CS210 Instructor: Ravi Gandham
// Assignment: Date Assigned:
// Programmer: Date Submitted:
#include<iostream>
#include <string>
using namespace std;
int main()
{
string word1;
string word2;
string word3;
string word4;
string stringEval;
cout << "Enter four words using spaces between them: " << endl;
cin >> word1 >> word2 >> word3 >> word4;
if (word1 > word2){
cout << "....." << word1;}
else
cout << "....." << word2;
if (word3 > word4){
cout << "....." << word3;}
else cout << "...." << word4;
/*stringEval.find
if ((word1 == 'A') && (word1 == 'a'))
*/
system("pause");
return 0;
}
It would be nice if you talked about the possible manipulations that we could do with strings.
Thank you
Hello everyone I am trying to do this assignment in the book: Write a program that reads four words (as character strings) and display them in increasing and decreasing alphabetical sequence.
I have done the 1st (easy) part but not sure how to go about displaying words in alphabetical order.
Here is what I’ve got so far:
int main()
{
string word1;
string word2;
string word3;
string word4;
string stringEval;
cout << "Enter four words using spaces between them: " << endl;
cin >> word1 >> word2 >> word3 >> word4;
Thank you for your help!
Hello,
I am trying to do this assignment in the book. My objective is to create an interactive program which will calculate areas of a square or a triangle depending on the user input 's' or 't'. I am gone about 40% of the book so they dont expect me to use any kind of fancy stuff, just using If statement
Anyhow, here is my code and the errors are C2676 and C2784 in Visual Studio
Please tell me what i am doing wrong there
Thank you
// greg lyukshin
// chapter 4.4 program 2
// compound IF statement for area of the square and triangle
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
char s,
t;
float area,
side,
base,
height;
string letter;
cout << "enter either 's' to find area of square or 't' to find area of triangle: " << endl;
cin >> letter;
if(letter == 's')
{ cout << "enter side: " << endl;
cin >> side;
area = pow(side,2);
cout << "area of square is " << area << endl;
}
else
if(letter == 't')
{ cout << "enter base: " << endl;
cin >> base;
cout << "enter height: " << endl;
cin >> height;
area = (1/2) * base * height;
cout << "area of triangle is " << area << endl;
}
system("pause");
return 0;
}
Another question:
how do i tell the string the rounding criteria?
For example, 2.5632 is rounded to 2.56, while 2.5652 is 2.57.
Any kind of help will be appreciated
Oh thats right!
Thanks a bunch!
Hello,
I am trying to solve an assignment in a book.
It is asking me to write a program that takes a positive number with fractional part, which would round it to two decimal places. For example, 3.4256 to 3.43. Now, the thing that confuses me is that this past chapter talked about functions and a little bit about strings. My question is if there is a separate function that does it or is it related to strings somehow?
Thank you for your help
Hello everyone,
Could you please explain to me how to write the user defined functions with multiple arguments? (specifically with 2 or 3 input arguments). And also, how to make one function to manipulate different data each time it is called? (for example area of bigger circle minus area of the smaller circle with one findArea function) To be specific, can you show me Prototype, function definition, and function call?
My C++ book doesn't explain it clearly.
Thank you very much