Hy i'm a beginner in c++ and this question may sound silly but i have a problem.
My cursor is yellow and every time i type a character the nextone is deleted automatically and so on. i think it's an option enabled but i can't find it; can someone tell me what to do?
SInce that really didn't count as a C++ type question I can add this to the discussion.
I am having an incrementation problem in this code. It is supposed to increment the hour and for each hour supply the distance traveled. As it stands it just displays the hours and the total distance traveled. Yes it's homework and no I wouldn't want anyone to write it but a small hint on why it won't increment and a swift kick in the ... right direction would be appreciated.
#include<iostream>
usingnamespace std;
int main()
{
int speed = 0, distance, time = 1; //declare variables
cout <<"How fast will the vehicle be traveling? " << endl; //ask for user input
cin >> speed; //user input
cout << "How long will it travel? " << endl; //ask for user input
cin >> time; // user input
distance = speed * time; //formula
if (speed < 0 || time < 1) //cannot accept a negative value for speed or any value less than 1 for time travelled
{
cout << "Please re-enter your data! The value you have chosen is not valid. "<< endl;
//ask user to re-enter input
}
else (time >= 1 && speed >= 0);// do not know if this works or is necessary as it seems to have no affect on output
{
cout << "Hours " << "\t\t" << "Distance Traveled " << endl; //headings for output
cout << time++ << "\t\t" << distance++ << endl; //supposed to increment output but it doesnt
}
[code]
So my call should occur before the else? Could I change the else to an if and put that code before the warning? It would the compile it first and "read" the time++ before the warning statement. Otherwise I'm not sure where it should go.
1) Just use variable+1 if you don't actually need to modify the data
2) Use a pre-increment
3) Use a post-increment, but put it before the cout, (basically simulating a pre-increment)