I am trying, I really am , but I cant sort this out. I am trying to add a function to my code, but i cant get it right. I think i am missing a function.
I just want the do you want to proceed yes or no? To work , it yes then proceed if no then return to the start of the question.. I have removed all the horrible attempts and added codes to try and get it working. This is the code.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fstream>
usingnamespace std;
int main()
{
string line;
ifstream myfile ("example1.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
cout << "Test software" << endl;
struct tm *current;
time_t now;
time(&now);
current = localtime(&now);
printf("The current time is: %i:%i\n", current->tm_hour, current->tm_min, current->tm_sec);
int thisisanumber;
cout<<"Please enter reading on Tank number 1: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n""Do you wish to proceed?";
cin.get();
cout<<"Please enter reading on Tank number 2: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n""Do you wish to proceed?";
cin.get();
cout<<"Please enter reading on Tank number 3: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n""Do you wish to proceed?";
cin.get();
}
I suppose you're trying to do something like this : -
1 2 3 4 5 6 7 8 9
char response;
do {
cout<<"Please enter reading on Tank number 1: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n""Do you wish to proceed?";
cin >> response; } while (response == 'n');
printf("The current time is: %i:%i\n", current->tm_hour, current->tm_min, current->tm_sec);
int thisisanumber;
char response;
do {
cout<<"Please enter reading on Tank number 1: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n"
"Do you wish to proceed?";
cin >> response; } while (response == 'n')
char response;
do {
cout<<"Please enter reading on Tank number 1: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n"
"Do you wish to proceed?";
cin >> response; } while (response == 'n')
char response;
do {
cout<<"Please enter reading on Tank number 1: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n"
"Do you wish to proceed?";
cin >> response; } while (response == 'n')
}
errors are as follows.
tank 3.cpp||In function 'int main()':|
tank 3.cpp|49|error: expected ';' before 'char'|
tank 3.cpp|49|error: redeclaration of 'char response'|
tank 3.cpp|39|error: 'char response' previously declared here|
tank 3.cpp|60|error: expected ';' before 'char'|
tank 3.cpp|60|error: redeclaration of 'char response'|
tank 3.cpp|39|error: 'char response' previously declared here|
tank 3.cpp|69|error: expected ';' before '}' token|
||=== Build finished: 7 errors, 0 warnings ===|
The previoulsy delcared could be a case of telling the same thing over and over again?
Almost there guys! Thanks for the help thus far. All that I am currently having a problem with is that the yes response is basically any key other than "n" , which is not really that bad , it is just a keyboard filled will yes keys , like a mine field.
Any way I can specify that it musy be "y" ? I will post the code, if you see the problem and understand what needs to be done , please for my sanity just add show me what needs to be added and to what line or lines please....
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fstream>
usingnamespace std;
int main()
{
string line;
ifstream myfile ("example1.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
cout << "Test software" << endl;
struct tm *current;
time_t now;
time(&now);
current = localtime(&now);
printf("The current time is: %i:%i\n", current->tm_hour, current->tm_min, current->tm_sec);
int thisisanumber;
char response;
do {
cout<<"Please enter reading on Tank number A: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n""Do you wish to proceed?";
cin >> response; } while (response == 'n');
cin.get();
do {
cout<<"Please enter reading on Tank number B: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n""Do you wish to proceed?";
cin >> response; } while (response == 'n');
cin.get();
do {
cout<<"Please enter reading on Tank number C: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n""Do you wish to proceed?";
cin >> response; } while (response == 'n');
}
I am sure something like the code below may help but I am not sure if anything else needs to be added before. and where..
cin >> response; } while (response =='y');