• 0

C++ If Statement Question


Question

Hey Guys and girls,

 

I've been working on a tool for a friends project, and I'm running into a few problems. My knowledge is pretty basic with C++. I'm doing my best.

I was looking at several different sources. I've never written a program that writes any information, I've only written tools that accept input and output. Very sloppily but my professors accepted it. Posting the code below.

Source 1

 

Source 2

#include <iostream>
#include <string>
#include <ostream>
#include <fstream>
#include <cstdio>




using namespace std;

//char projName; (not in use yet)

int main(){
	cout << "Hello! Welcome to the Media Rename Tool!" "\n";
	//Here is where the location is set.
	
	
	// Handles whether or not it's a single file or multiple..
	cout << "Is this a single file or multiples?\n";
	string input;
	cin >> input;
	if (input == "Single"){

	}
	else if (input == "Multiple"){

	}

	else {
		cout << "You didn't enter Single or Multiple. Please try again" << endl;
	}
	//Here is where the name would be changed
	
	
	
	//Here is where you would save the name, if you wanted too.
	cout << "Would you like to save the file name? Yes or No."
	string savename;
	cin >> savename;
	if (savename == "Yes"){

	}
	else if (savename == "No"){

	}

	else {
		cout << "You didn't enter an answer. Please try again" << endl;
	}
	
	//Handles the quality of the files.
	cout << "Is the file 480p, 720p, 1080p or Other?\n";
	string Input;
	cin >> Input;
	if (Input == "480p"){
		
	}
	else if (Input == "720p"){

	}
	else if (Input == "1080p"){

	}
	else if (Input == "Other"){
		cout << "Enter Value Below." << endl;
		string qValue;
		cin >> qValue;
	}

	else {
		cout << "You didn't enter 480p, 720p, 1080p or Other. Please try again" << endl;
	}
	
	//Here is where the finalized name would appear, and generate the log file.
	system("pause");
	return 0;

}

I've commented the sections where different commands would run.

I'm not sure how to go about setting a file location, and keeping that location stored in the program. Would I set a variable, i.e. "defaultLocation"? I'm also wanting to have names saved, i.e. Video 1 = xxxxxxxx, Video 2 = yyyyyyyy, Video 3 = zzzzzzz all the way up to say 999.

 

 

Anyways, to the problem..

 

  Quote
NPP_SAVE: E:\Work Projects\GXS-Toolbox\main.cpp
g++ -o "E:\Work Projects\GXS-Toolbox\main" "E:\Work Projects\GXS-Toolbox\main.cpp" -static
Process started >>>
E:\Work Projects\GXS-Toolbox\main.cpp: In function 'int main()':
E:\Work Projects\GXS-Toolbox\main.cpp:39:2: error: expected ';' before 'string'
  string savename;
  ^
E:\Work Projects\GXS-Toolbox\main.cpp:40:9: error: 'savename' was not declared in this scope
  cin >> savename;
         ^
<<< Process finished.
================ READY ================

Why am I getting this exactly? I'm having a brainfart.

 

 

GitHub - BinaryData

Link to comment
https://www.neowin.net/forum/topic/1264958-c-if-statement-question/
Share on other sites

4 answers to this question

Recommended Posts

  • 0

The error message couldn't be much more specific :p.

 

E:\Work Projects\GXS-Toolbox\main.cpp:39:2: error: expected ';' before 'string'
  string savename;
  ^
cout << "Would you like to save the file name? Yes or No."
string savename;
You're missing the semi-colon on the end of the cout line.
  • 0
  On 17/07/2015 at 12:12, ZakO said:

The error message couldn't be much more specific :p.

 

E:\Work Projects\GXS-Toolbox\main.cpp:39:2: error: expected ';' before 'string'
  string savename;
  ^
cout << "Would you like to save the file name? Yes or No."
string savename;
You're missing the semi-colon on the end of the cout line.

 

*FACEPALM* 

Can we pretend I didn't post that? xD

  • 0
  On 17/07/2015 at 12:15, BinaryData said:

*FACEPALM* 

Can we pretend I didn't post that? xD

Don't worry we all make that mistake. Missing line terminators (and white space in the case of Python) are the bane of a programmer's life. Still it's quite gratifying when you finally track the thing down :D

 

  Quote

I'm not sure how to go about setting a file location, and keeping that location stored in the program. Would I set a variable, i.e. "defaultLocation"? I'm also wanting to have names saved, i.e. Video 1 = xxxxxxxx, Video 2 = yyyyyyyy, Video 3 = zzzzzzz all the way up to say 999.

Well there are a few ways.

a) Accept an argument (argv) in your program from the command line, script, or launcher. You could also save that location in a configuration file as the default for subsequent runs of the program.

 

b) Store it in the working directory of the program or another predefined OS-specific location. The latter can be obtained through various standard API's / environmental variables.

 

c) Tying in with a), you could provide a configuration file for the user to edit where they can specify that information. Of course you would also provide defaults.

 

d) Get the file name/path from the user. Can be tedious for them though.

 

As for storing the names in your program, you'll want some kind of data structure. Probably a list, array, or hash map depending on what your intentions with it are. If you intend to do a lot of inserts/deletions, then a list or map would be best. An array would be better suited to a more static dataset.

  • 0
  On 17/07/2015 at 13:28, simplezz said:

Don't worry we all make that mistake. Missing line terminators (and white space in the case of Python) are the bane of a programmer's life. Still it's quite gratifying when you finally track the thing down :D

 

Well there are a few ways.

a) Accept an argument (argv) in your program from the command line, script, or launcher. You could also save that location in a configuration file as the default for subsequent runs of the program.

 

b) Store it in the working directory of the program or another predefined OS-specific location. The latter can be obtained through various standard API's / environmental variables.

 

c) Tying in with a), you could provide a configuration file for the user to edit where they can specify that information. Of course you would also provide defaults.

 

d) Get the file name/path from the user. Can be tedious for them though.

 

As for storing the names in your program, you'll want some kind of data structure. Probably a list, array, or hash map depending on what your intentions with it are. If you intend to do a lot of inserts/deletions, then a list or map would be best. An array would be better suited to a more static dataset.

Hmm.. I was hoping to avoid configuration files, and pre-defined locations. Configuration files can be deleted or things can go wrong. I learned that lesson when playing a video game. They made a boot.ini file, and it overwrote the Windows boot.ini. :p

 

Getting the file name/path from the user can be tedious, however the names would be static. The names wouldn't be deleted for 3 - 4 months at a time, some times up to 6 months or longer. I understand your point with the configuration file.

Hmm.. Storing them in a list or map sounds like it'd be best, if I don't go the configuration route. My brain has all these wonderful ideas, it's putting them into code that I struggle with. I've been reading a lot about renaming files, but I'm having no luck there.

 

I'll read up on lists and hash maps. Though, I probably won't understand them, haha. Right now, I'm tackling the renaming feature. I can't seem to get it to do what I want.

I need blah blah text + user_inputed_name + quality type and it be .mkv. I'm still stuck at the cin >> newName; part, haha.

This topic is now closed to further replies.