• 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.
  • Posts

    • Amazon lays off more staff across Goodreads and Kindle divisions by Hamid Ganji Dozens of Amazon employees working on the retailer's book divisions have been laid off. As reported by Reuters, Amazon confirmed that it's cutting jobs across the Goodreads review site and Kindle units, which impacts fewer than 100 workers. Amazon says the recent layoffs across Goodreads and Kindle divisions are meant to improve efficiency and streamline operations. The giant retailer has constantly reduced staff across various divisions over the past few years. According to CEO Andy Jassy, reducing headcounts helps the company to eliminate bureaucracy. "As part of our ongoing work to make our teams and programs operate more efficiently and to better align with our business roadmap, we've made the difficult decision to eliminate a small number of roles within the Books organization," an Amazon spokesperson said. Layoffs recently impacted employees in Amazon's Wondery podcast division, devices and services units, communications, and in-store staff. However, Amazon's Q1 results show the retailer has added about 4,000 jobs compared to Q4 2024. After the Covid pandemic settled down, many companies began laying off thousands of staff they hired during the pandemic to respond to growing demands. The layoff trend among tech firms still exists today, and AI has amplified it. The latest data shows that in 2025, about 62,832 tech employees were laid off across 141 tech companies. Also, 152,922 tech employees across 551 companies were laid off in 2024. More layoffs are expected to occur due to declining economic growth, tariffs, and the expansion of AI across companies. Amazon is also gearing up to double down in AI investments and robotics. The company has recently announced the forming of a new agentic AI team to develop an agentic AI framework for use in robotics. Also, a new report by The Information indicates that Amazon has begun testing humanoid robots for package delivery.
    • Major Privacy 0.98.1.1 Beta by Razvan Serea MajorPrivacy is a cutting-edge privacy and security tool for Windows, offering unparalleled control over process behavior, file access, and network communication. It is a continuation of the PrivateWin10 project. By leveraging advanced kernel-level protections, MajorPrivacy creates a secure environment where user data and system integrity are fully safeguarded. Unlike traditional tools, MajorPrivacy introduces innovative protection methods that ensure mounted encrypted volumes are only accessible by authorized applications, making it the first and only encryption solution of its kind. MajorPrivacy – Ultimate Privacy & Security for Windows key features Process Protection – Isolate processes to block interference from unauthorized apps, even with admin privileges. Software Restriction – Block unwanted apps and DLLs to ensure only trusted software runs. Revolutionary Encrypted Volumes Secure Storage – Create encrypted disk images for sensitive data. Exclusive Access – Unlike traditional tools, only authorized apps can access mounted volumes—blocking all unauthorized processes. File & Folder Protection – Lock down sensitive files and prevent unauthorized access or modifications. Advanced Network Firewall – Control which apps can send or receive data online. DNS Monitoring & Filtering – Track domain access and block unwanted sites (Pi-hole compatible filtering coming soon). Tweak Engine – Disable telemetry, cloud integration, and invasive Windows features for better privacy. Why MajorPrivacy? Kernel-Level Security – Protects at the deepest system level. Unmatched Encryption Protection – Keeps mounted volumes safe from all unauthorized access. Full System Control – Block, isolate, or restrict processes as needed. Enhanced Privacy – Stops Windows & apps from collecting unnecessary data. Perfect for privacy-conscious users, IT pros, and anyone who wants total system control. Major Privacy 0.98.1.1 Beta changelog: The 0.98.1 release of MajorPrivacy introduces significant enhancements and a number of critical fixes aimed at improving usability, localization, and system integration. A major new feature is the introduction of full translation support, allowing the application interface and tweaks to be localized into multiple languages. Initial translations include AI-assisted German and Polish versions, a community-contributed Turkish translation, and Simplified Chinese. Users interested in contributing translations or adding new languages are encouraged to participate via the forum. This version also improves compatibility and deployment by bundling the Microsoft Visual C++ Redistributable with the installer, which is required for the ImDisk user interface. Several important bugs have been resolved. The installer now correctly removes the driver during uninstallation. Tweak definitions have been cleaned up for better consistency. A number of networking issues were addressed, including failures related to network shares and incorrect handling of mapped drive letters. It is now required to use full UNC paths for defining rules involving shared resources. Additionally, configuration persistence issues on system shutdown have been fixed, as well as problems affecting protected folder visibility and rule precedence involving enclave conditions. Finally, the underlying driver code has been refactored, laying the groundwork for better maintainability and future enhancements. MajorPrivacy-v0.98.1.1.exe (0.98.1a) hotfix for #71 Download: Major Privacy 0.98.1.1 Beta | 47.4 MB (Open Source) View: MajorPrivacy Home Page | Github Project page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • OpenAI responds to The New York Times' ChatGPT data demands by Pradeep Viswanathan The New York Times has sued OpenAI for the unauthorized use of its news articles to train large language models. As part of the ongoing lawsuit, the NYT recently asked the court to require OpenAI to retain all ChatGPT user content indefinitely. The NYT's argument is that they may find something in the data that supports their case. Brad Lightcap, COO of OpenAI, wrote the following regarding the NYT's sweeping demand: OpenAI has already filed a motion asking the Magistrate Judge to reconsider the preservation order, since indefinite retention of user data breaches industry norms and its own policies. Additionally, OpenAI has also appealed this order with the District Court Judge. Until OpenAI wins its appeal, it will be complying with the court order. The content defined by the court order will be stored separately in a secure system and will be accessed or used only for meeting legal obligations. Only a small, audited OpenAI legal and security team will be able to access this data as necessary to comply with our legal obligations. As of early 2025, ChatGPT has over 400 million weekly active users, and this data retention order will affect a significant number of them. OpenAI confirmed that ChatGPT Free, Plus, Pro, and Teams subscription users, and developers who use the OpenAI API (without a Zero Data Retention agreement) will be affected by this order. ChatGPT Enterprise, ChatGPT Edu, and API customers who are using Zero Data Retention endpoints will not be affected by this court change.
  • Recent Achievements

    • First Post
      Uranus_enjoyer earned a badge
      First Post
    • Week One Done
      Uranus_enjoyer earned a badge
      Week One Done
    • Week One Done
      jfam earned a badge
      Week One Done
    • First Post
      survivor303 earned a badge
      First Post
    • Week One Done
      CHUNWEI earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      428
    2. 2
      +FloatingFatMan
      238
    3. 3
      ATLien_0
      212
    4. 4
      snowy owl
      211
    5. 5
      Xenon
      159
  • Tell a friend

    Love Neowin? Tell a friend!