hello guys, i am having some problems with my code (i am an absolute beginner by the way). i am creating a program where the user gives me the input of his "buying price" and "sale Price" and i tell him how much profit he made. i am trying to make it in a way so that whenever a user puts in an alphabet it just tells him invalid input and also one more problem i encountered was that when i ask the user if they would like to calculate again, when the input is yes it asks for the amount of products and then goes straight to amount of investment instead of going through the whole process again. please help me out if you can. thank you
#include "stdafx.h"
#include <iostream>
#include <limits>
usingnamespace std;
int main()
{
float money = 0, convert = 0;
float investment = 0;
float salePrice = 0;
float price = 0;
float total = 0;
float goods = 0;
float amountLeft = 0;
float profit = 0, nprofit = 0;
int c = 1;
char option = 'y';
do{
do{
cout << "Enter the amount of product you bought" << endl;
cin >> goods;
} while (goods <= 0);
while (c <= goods){
do{
cout << " Enter the price for product " << c << endl;
cin >> price;
} while (price <= 0);
do{
cout << " Enter the amount you sold for product" << c << endl;
cin >> salePrice;
} while (salePrice <= 0);
if (price < salePrice){
nprofit = salePrice - price;
cout << " you made RM" << nprofit << " profit on this product" << endl;
}
elseif (price > salePrice){
nprofit = price - salePrice;
cout << "you made no profit on this product" << "( you lost RM" << nprofit << ")" << endl;
}
else{
cout << "you made no profit neither was their any loss for this product" << endl;
}
total = total + price;
c++;
}
do{
cout << "Enter the amount of money you have for investment" << endl;
cin >> investment;
} while (investment <= 0);
amountLeft = investment - total;
if (amountLeft <= 0){
cout << "you have no money left for further investment" << endl;
}
elseif (amountLeft > 0){
cout << "you still have RM" << amountLeft << " amount left for investment" << endl;
}
else{
}
cout << "would you still like to invest in a different product (y/n)" << endl;
cin >> option;
}while (option == 'y' );
cout << "" << endl;
cout << "to help you trade successfuly, this is a simple currency converter from RM to US dollars" << endl;
do{
cout << "how much do you want to convert?" << endl;
cin >> money;
} while (money <= 0);
convert = money * 0.31;
cout << "this is how much RM" << money << " is in USD : " << convert << endl;
cout << "Thank you for using this Program, goodluck with your business." << endl;
return 0;
}
/*
if (cin.fail()) {
cin.clear();
cin.ignore();
cout << endl << "That wasn't a number " << endl;
}
* ( this is the code i tried)\
*/